Trying to create users and groups with vars inline…this is not working…what am I missing here?
— # Users and Groups
- hosts: localhost
become: yes
vars:
groups: - devops
- dbadbmins
- serveradmins
users:
-
frank
-
joe
-
dave
tasks: -
name: Create groups
group:
name: “{{ item.groups }}”
state: present
with_items: “{{groups}}”
ignore_errors: yes -
name: Create users
user:
name: “{{ item.user }}”
state: present
with_items: “{{users}}”
Output -
PLAY [localhost] *********************************************************************
TASK [Gathering Facts] ***************************************************************
ok: [localhost]
TASK [Create groups] *****************************************************************
fatal: [localhost]: FAILED! => {“failed”: true, “msg”: “the field ‘args’ has an invalid value, which appears to include a variable that is undefined. The error was: ‘ansible.vars.unsafe_proxy.AnsibleUnsafeText object’ has no attribute ‘groups’\n\nThe error appears to have been in ‘/etc/ansible/playbooks/usersgroups.yml’: line 15, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: Create groups\n ^ here\n”}
…ignoring
TASK [Create users] ******************************************************************
fatal: [localhost]: FAILED! => {“failed”: true, “msg”: “the field ‘args’ has an invalid value, which appears to include a variable that is undefined. The error was: ‘ansible.vars.unsafe_proxy.AnsibleUnsafeText object’ has no attribute ‘user’\n\nThe error appears to have been in ‘/etc/ansible/playbooks/usersgroups.yml’: line 22, column 7, 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 users\n ^ here\n”}
to retry, use: --limit @/etc/ansible/playbooks/usersgroups.retry