Hey All
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"}
roles/linux/tasks/main.yml
---
- name: Linux VM setup
hosts: centos7-x64-template
remote_user: root
tasks:
- name: adding groups
include_vars:
file: our_groups.yml
group:
name: "{{ item.name }}"
state: present
gid: "{{ item.gid }}"
with_items: "{{ our_groups }}"
... roles/linux/vars/our_groups.yml
--
our_groups:
- name: devops
gid: 710
- name: developers1
gid: 711
- name: developers2
gid: 712
- name: developers3
gid: 713
...
Thanks
John