I am trying to run a playbook locally but I want all the vars in the role's task/main.yml file to refer to a group_var in a specific inventory file.
Unfortunately the playbook is unable to access to the group_vars directory as if fail to recognize the vars specified in the role.
The command ran is the following:
/usr/local/bin/ansible-playbook --connection=local /opt/ansible/playbooks/create.yml -i ./inventory-file
but fails to find the group_vars in the /group_vars directory at the same directory level of the inventory file
fatal: [127.0.0.1]: FAILED! => {
"msg": "The task includes an option with an undefined variable. The error was: 'admin_user_name' is undefined\n\nThe error appears to have been in '/opt/roles/create/tasks/main.yml': line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n---\n- name: create org\n ^ here\n"
}
This is my configuration:
ansible-playbook 2.7.5
config file = /etc/ansible/ansible.cfg
configured module search path = ['/opt/ansible-modules']
ansible python module location = /usr/local/lib/python3.6/dist-packages/ansible
executable location = /usr/local/bin/ansible-playbook
python version = 3.6.3 (default, Oct 3 2017, 21:45:48) [GCC 7.2.0]
Any help is appreciated.
Thanks, dom
So, theoretically adding localhost in the inventory would have been a good solution, but in my specific case (and in general for large deployments) was not an option.
I also added --extra-vars "myvar.json"
but did not work either.
Turns out (evil detail...) that the right way to add a var file via command line is: --extra-vars "@myvar.json"
Posting it here in hope nobody else struggle days to find this solution.
Cheers, dom
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With