Reputation: 1636
fairly new to ansible.
having following role e.g.: my-role
- i have trouble overriding the default variables from the playbook
follwing files:
my-role/tasks/main.yml
my-role/defaults/main.yml
sample-playbook.yml
my-role/tasks/main.yml
- name: "Add Test User"
user: name={{ my_config_test_user }} comment="{{ my_config_test_user }}" group={{ my_config_test_user }}
my-role/defaults/main.yml
my_config_test_user: "test"
playbook:
- name: TestCase
hosts: all
remote_user: root
vars:
my_config_test_user: "override"
roles:
- my-role
in the task the value of my_config_test_user
stays test
instead of my expected result override
any hints?
regards
Upvotes: 8
Views: 25435
Reputation: 5596
In the current version of Ansible order of precedence says that the value of my_config_test_user
should be override not test so I think you probably have a typo somewhere. Maybe the variable is not spelled correctly?
I suggest removing defaults/main.yml temporarily to ensure that you do not get an undefined variable error. I would also suggest using the debug module to check the value of the variable in your tasks/main.yml
- debug: var={{ my_config_test_user }}
For reference here is the order of precedence (starting with the greatest) in the current version of Ansible:
Upvotes: 18