Skip to content

fix: [#181] use ansible_user variable instead of hardcoded username - #183

Merged
josecelano merged 1 commit into
mainfrom
181-fix-hardcoded-ansible-user-in-inventory-template
Nov 18, 2025
Merged

josecelano merged 1 commit into
mainfrom
181-fix-hardcoded-ansible-user-in-inventory-template

Conversation

@josecelano

Copy link
Copy Markdown
Member

Description

Fixes #181 - Removes hardcoded ansible_user: torrust from the inventory template and makes it configurable via the environment's SSH credentials.

Changes

Template Update

  • templates/ansible/inventory.yml.tera: Changed from hardcoded ansible_user: torrust to variable ansible_user: {{ansible_user}}

Data Structure Updates

  • InventoryContext struct: Added ansible_user: String field
  • InventoryContextBuilder: Added with_ansible_user() builder method
  • Error handling: Added MissingAnsibleUser error variant
  • Accessors: Added ansible_user() method

Production Code

  • create_inventory_context(): Now extracts username from ssh_credentials.ssh_username and passes it to the builder

Tests

  • Updated all unit tests to include ansible_user
  • Updated integration tests to use the variable
  • Added new test for missing ansible_user validation
  • Fixed all test templates to use {{ansible_user}} variable

Verification

✅ All 1150 unit tests pass
✅ All integration tests pass
✅ Pre-commit checks pass
✅ Manual E2E test verified with custom username testuser123
✅ Rendered inventory file correctly shows configurable username

Impact

Users can now specify custom SSH usernames (ubuntu, admin, etc.) in their environment configuration instead of being forced to use the hardcoded 'torrust' username.

Before: SSH connections always used hardcoded username "torrust"
After: SSH connections use the username specified in ssh_credentials.username from environment config

- Updated inventory template to use {{ansible_user}} variable
- Added ansible_user field to InventoryContext struct
- Updated all builders and tests to pass ansible_user
- Fixed hardcoded 'torrust' username in inventory.yml.tera
- Ansible now respects ssh_credentials.username from environment config

This allows users to specify custom usernames (ubuntu, admin, etc.)
instead of being forced to use 'torrust'.
@josecelano josecelano self-assigned this Nov 18, 2025
@josecelano

Copy link
Copy Markdown
Member Author

ACK 06ccd74

@josecelano
josecelano merged commit 45d45a2 into main Nov 18, 2025
@josecelano
josecelano deleted the 181-fix-hardcoded-ansible-user-in-inventory-template branch April 15, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix Hardcoded ansible_user in Inventory Template

1 participant