Variable role of the uploaded file
pretty new to the truth. having the following role, for example: my-role
- i have a problem overriding default variables from 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 / default / 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 my_config_test_user
remains test
instead of the expected resultoverride
any clues?
considers
source to share
The current version of Ansible order of Priorence says that the value my_config_test_user
should be overridden not test , so I think you probably have a typo somewhere. Maybe the variable is written incorrectly?
I suggest temporarily removing defaults / main.yml to ensure you don't get an undefined variable error. I also suggest using a debug module to check the value of a variable in your tasks /main.yml
- debug: var={{ my_config_test_user }}
For reference: the order of precedence (highest starting) in the current version of Ansible:
- Vars set on command line -e foo = set_on_cmd_line
- Vars set in vars_files: block in game
- Vars set to vars: block in the game
- Vars set to host_vars /
- Vars set to group_vars /
- The default role vars role /.../ defaults / main.yml
source to share