I’m new to Ansible so I may be trying to do things completely wrong… Ideally I’d like “adding groups” to be a stand alone task, so I can call it with the group file name from other tasks but lets crawl before we run.
I need to add a large number of groups to certain machines (users too, but groups come first). The GID is already defined so I need to pass that along with the group.
I get this error when I try with my code below, I’ve tried replacing “item” with “our_groups” but get the same error just a change it what is undefined.
[unix@ansible01:~]$ ansible-playbook -i ansible/inventories/hosts ansible/roles/linux/tasks/main.yml <SNIP> TASK [adding groups] ********************************************************************************************************************************************** fatal: [centos7-x64-template]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'item' is undefined\n\nThe error appears to have been in '/automation/unix/ansible/roles/linux/tasks/main.yml': line 22, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: adding groups\n ^ here\n"}
The formatting is tripping me up for sure, was hoping Atom would do a better job at keeping me aligned there, but it’s a bit more, you have an error fix it at this point.
I get a different error now when I run it, one I fought with before, the file exists for sure:
PLAY [Linux VM setup] *********************************************************************************************************************************************
TASK [adding groups] **********************************************************************************************************************************************
fatal: [centos7-x64-template]: FAILED! => {“ansible_facts”: {}, “ansible_included_var_files”: , “changed”: false, “message”: “Could not find or access ‘our_groups.yml’\nSearched in:\n\t/automation/unix/ansible/roles/linux/tasks/vars/our_groups.yml\n\t/automation/unix/ansible/roles/linux/tasks/our_groups.yml\n\t/automation/unix/ansible/roles/linux/tasks/vars/our_groups.yml\n\t/automation/unix/ansible/roles/linux/tasks/our_groups.yml on the Ansible Controller.\nIf you are using a module and expect the file to exist on the remote, see the remote_src option”}
to retry, use: --limit @/automation/unix/ansible/roles/linux/tasks/main.retry
PLAY RECAP ********************************************************************************************************************************************************
centos7-x64-template : ok=1 changed=0 unreachable=0 failed=1
`
I expect the error, you are referring to the file that is not in the
expected paths, it should either be in a vars/ directory adjacent to
the play you are executing or you should 'include_vars' from within
the 'linux' role.
Ansible will not search all your roles for files, specially in roles
that are not referenced in the play.
you can keep it in a vars dir adjacent to your play, or when the
'linux' role you can keep it where it was, you cannot do what you were
doing wich was keep it in a role and use it from an unrelated play.