Skip to content

Instantly share code, notes, and snippets.

@lakshmi-kannan
Created January 4, 2017 22:14
Show Gist options
  • Save lakshmi-kannan/3e44241db21cf99bf5bc3f5866d23f00 to your computer and use it in GitHub Desktop.
Save lakshmi-kannan/3e44241db21cf99bf5bc3f5866d23f00 to your computer and use it in GitHub Desktop.
ubuntu@test:/vagrant$ cat example_runbook.yml
---
- hosts: all
sudo: true
vars:
users_admin_sudo_password: false
roles:
- role: willshersystems.users
users:
- name: carl
uid: 1010
comment: 'Carl Crisp'
is_admin: yes
groups:
- beancounters
- name: ec_user
state: absent
users_groups:
- name: devs
gid: 1200
users_ssh_keys:
- name: carl
keys:
- ssh-rsa AAAA....... [email protected]
ubuntu@test:/vagrant$ ansible-playbook -c local -i "$HOSTNAME," /vagrant/example_runbook.yml
[DEPRECATION WARNING]: Instead of sudo/sudo_user, use become/become_user and make sure become_method is 'sudo' (default).
This feature will
be removed in a future release. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
PLAY [all] *********************************************************************
TASK [setup] *******************************************************************
ok: [test]
TASK [willshersystems.users : Load OS specific values] *************************
ok: [test] => (item=/etc/ansible/roles/willshersystems.users/vars/Debian.yml)
TASK [willshersystems.users : Create groups] ***********************************
fatal: [test]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'unicode object' has no attribute 'name'\n\nThe error appears to have been in '/etc/ansible/roles/willshersystems.users/tasks/add_groups.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 groups\n ^ here\n"}
to retry, use: --limit @/vagrant/example_runbook.retry
PLAY RECAP *********************************************************************
test : ok=2 changed=0 unreachable=0 failed=1
ubuntu@test:/vagrant$ ansible-playbook --version
ansible-playbook 2.2.0.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
ubuntu@test:/vagrant$
@lakshmi-kannan
Copy link
Author

lakshmi-kannan commented Jan 4, 2017

ubuntu@test:/vagrant$ cat /etc/ansible/roles/willshersystems.users/tasks/add_groups.yml
---
- name: Create groups
  group:
    name: "{{ item.name }}"
    state: "{{ item.state | default('present') }}"
    gid: "{{ item.gid | default(omit) }}"
    system: "{{ item.system | default(omit) }}"
  with_items: users_groups
  when: item.state|default('present') != "absent"

- name: Create per-user groups
  group:
    name: "{{ item.name }}"
    state: "{{ item.state | default('present') }}"
    gid: "{{ item.gid | default(item.uid) | default(omit) }}"
    system: "{{ item.system | default(omit) }}"
  with_items: users
  when: >
    users_per_user_groups == true and
    item.state|default('present') != 'absent'
ubuntu@test:/vagrant$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment