I would also say that best practice would be to put host specific vars within host_vars/hostname as opposed to within roles.
With roles I put my default vars within defaults and anything static within my role which will not change goes within the vars folder. If there are host or group specific vars, put them in host_vars or group_vars this way if someone else has to read your code they do not need to dig in the depths of roles to figure out where the vars were defined. Kind Regards On Wednesday, 14 December 2016 07:50:32 UTC, Alexander H. Laughlin wrote: > > Hello Elliott, > > I have written a bit of code that may be helpful to you. You may find it > here: > https://github.com/gahan-corporation/ansible-development/tree/master/work/elliott-barrare > > Hope it helps. Best of luck to you! > > > > On Monday, December 12, 2016 at 5:29:00 PM UTC-8, Elliott Barrere wrote: >> >> Hi there — >> >> I have a variable called pbis_require_membership_of defined in >> group_vars/all.yaml, and it is overridden for a particular host under >> role/vars/hostname, however neither of the values are being used at >> runtime and the module errors with pbis_require_membership_of' is >> undefined >> >> (ansible)[ansible@ansible-server code]$ grep -R >> pbis_require_membership_of group_vars/ >> >> group_vars/all/all.yaml:pbis_require_membership_of: '"DOMAIN\\teaminfra" >> "DOMAIN\\LinuxAdmins"' >> >> (ansible)[ansible@ansible-server code]$ grep -R >> pbis_require_membership_of roles/linux-pbis/vars/hostname >> >> pbis_require_membership_of: '"DOMAIN\\teaminfra" "DOMAIN\\LinuxAdmins" >> "DOMAIN\\StorageAdmins"' >> >> >> However, the following occurs when I try to reference it at runtime: >> >> TASK [linux-pbis : debug pbis_require_membership_of] >> ****************************************************************************************************************************************************************************** >> >> task path: roles/linux-pbis/tasks/main.yaml:62 >> >> ok: [hostname] => { >> >> "pbis_require_membership_of": "VARIABLE IS NOT DEFINED!" >> >> } >> ... >> >> TASK [linux-pbis : copy temp config file] >> ****************************************************************************************************************************************************************************** >> >> task path: roles/linux-pbis/tasks/reconfig_pbis.yaml:1 >> >> fatal: [hostname]: FAILED! => {"failed": true, "msg": "The conditional >> check 'require_membership_of.stdout != pbis_require_membership_of' failed. >> The error was: error while evaluating conditional >> (require_membership_of.stdout != pbis_require_membership_of): >> 'pbis_require_membership_of' is undefined\n\nThe error appears to have been >> in 'roles/linux-pbis/tasks/reconfig_pbis.yaml': line 1, 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: copy temp config file\n ^ >> here\n"} >> >> to retry, use: --limit @playbooks/linux/linux_pbis.retry >> >> >> >> I've recently updated from Ansible 2.1 to the latest (using git pull), which >> may or may not have been when this issue started. >> >> Any thoughts on why this variable is not getting set correctly? >> > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/09916ab4-f9cf-48b9-99c6-c7d71d33b072%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
