ansible-role-common/tasks/users.yml
2020-03-24 00:55:53 +01:00

49 lines
No EOL
1.2 KiB
YAML

---
- name: 'Install required packages'
pkgng: name={{item}} state=present
with_items:
- sudo
when: ansible_facts['os_family'] == 'FreeBSD'
- name: 'Allow wheel group to do passwordless sudo'
lineinfile:
dest: /usr/local/etc/sudoers
state: present
regexp: '^%wheel'
line: '%wheel ALL=(ALL) NOPASSWD:ALL'
validate: visudo -cf %s
when: ansible_facts['os_family'] == 'FreeBSD'
- name: 'Allow wheel group to do passwordless sudo'
lineinfile:
dest: /etc/sudoers
state: present
regexp: '^%wheel'
line: '%wheel ALL=(ALL) NOPASSWD:ALL'
validate: visudo -cf %s
when: ansible_facts['os_family'] == 'Debian'
- name: 'Create users with corresponding groups'
user:
name: "{{ item }}"
groups: users
with_items: "{{ users }}"
- name: 'Add corresponding authorized_keys to each user'
authorized_key:
user: "{{ item }}"
state: present
key: "{{ lookup('file', 'public_keys/id_{{ item }}.pub') }}"
with_items: "{{ users }}"
- name: 'Ensure that wheel group is existing'
group:
name: wheel
state: present
- name: 'Add sudoers user to wheel group'
user:
name: "{{ item }}"
groups: wheel
append: yes
with_items: "{{ sudoers }}"