---
unix_groups:
- group: general
state: present
gid: 1500
unix_users:
- user: fred
state: present
uid: 5000
group: general
root_access: restricted
- user: barney
state: present
uid: 5001
group: general
root_access: none
- user: wilma
state: present
uid: 5002
group: general
root_access: full
- name: Pull in user/group variables from role_vars
include_vars: main.yml
- name: Create Unix groups from the groups.yml file
action: group name={{ item.group }} state={{ item.state }} gid={{ item.gid }}
with_items: unix_groups
- name: Create Unix users from the users.yml file
action: user name={{ item.user }} state={{ item.state }} group={{ item.group | default(None) }} uid={{ item.uid | default(None) }} shell=/bin/bash expires=0
with_items: unix_users
- name: Create sudoers file if the user is allowed root access
template: src=../templates/sudoers-{{ item.root_access|default(None) }}.j2 dest=/etc/sudoers.d/{{ item.user }} owner=root group=root mode=0440
when: item.state == "present" and (item.root_access|default(None) == "full" or item.root_access|default(None) == "restricted")
with_items: unix_users
- name: Revoke root access if user is not allowed it
file: dest=/etc/sudoers.d/{{ item.user }} state=absent
when: item.state != "present" or (item.root_access|default(None) != "full" and item.root_access|default(None) != 'restricted')
with_items: unix_usersTASK: [users | Create Unix users from the users.yml file] *********************
fatal: [ralph] => error while evaluating conditional: inventory_hostname in item.value.access_to
FATAL: all hosts have already failed -- aborting
- name: debug output
debug: msg="access to is {{item.access_to }}"
with_items: unix_users "msg": "access to is ['dev_hosts', 'test_hosts', 'uat_hosts']"
Hi,
have you thought about managing those users with LDAP and sssd? The permissions could be managed with groups.
Maybe this approach is easier to maintain. In case of on or off boarding, just create or disable the user. No need to run Ansible just because someone left your organization.
regards,
/mf
--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/0082cfa6-c60d-409b-a2f3-2d694c9540e4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
- name: Create Unix users from the users.yml file
action: user name={{ item.0.user }} state={{ item.0.state }} group={{ item.0.group | default(None) }} uid={{ item.0.uid | default(None) }} shell=/bin/bash expires=0
when: "item.1 == 'all' or inventory_hostname in groups[item.1]"
with_subelements:
- unix_users
- access_to