2018-11-28 02:51:33 +00:00
|
|
|
---
|
2018-12-13 04:52:32 +00:00
|
|
|
- import_playbook: dependencies.yml
|
|
|
|
|
2018-11-28 02:51:33 +00:00
|
|
|
- hosts: all
|
2019-09-01 17:43:53 +00:00
|
|
|
name: Update local user accounts and access controls
|
2018-12-11 05:48:37 +00:00
|
|
|
tasks:
|
2018-12-22 18:55:36 +00:00
|
|
|
- import_tasks: tasks/users-preprocessing.yml
|
2018-12-11 05:48:37 +00:00
|
|
|
|
2018-12-13 04:52:32 +00:00
|
|
|
- name: Create local user accounts
|
|
|
|
tags: users_create
|
2018-12-14 03:30:40 +00:00
|
|
|
become: true
|
2018-12-13 04:52:32 +00:00
|
|
|
block:
|
2018-12-11 05:48:37 +00:00
|
|
|
- name: Create groups
|
|
|
|
group:
|
|
|
|
name: "{{ item }}"
|
|
|
|
state: present
|
2019-09-01 17:43:53 +00:00
|
|
|
loop: "{{ targets + ['omni'] }}"
|
2018-12-11 05:48:37 +00:00
|
|
|
|
|
|
|
- name: Create users
|
|
|
|
user:
|
|
|
|
name: "{{ item.name }}"
|
|
|
|
comment: "{{ item.fullname | default('') }}"
|
|
|
|
shell: /bin/bash
|
|
|
|
groups: "{{ item.targets | intersect(targets) }} + {{ [ 'omni' ] if item.name != 'root' else [] }}"
|
|
|
|
system: "{{ item.svc | default('no') }}"
|
|
|
|
state: present
|
2018-12-13 05:50:43 +00:00
|
|
|
generate_ssh_key: "{{ 'yes' if generate_keys|bool == true else 'no' }}"
|
2018-12-13 04:52:32 +00:00
|
|
|
ssh_key_comment: "{{ item.name }}@{{ inventory_hostname }}"
|
|
|
|
ssh_key_bits: 4096
|
2019-09-01 17:43:53 +00:00
|
|
|
ssh_key_type: ed25519
|
2018-12-11 05:48:37 +00:00
|
|
|
password: "{{ item.password }}"
|
2019-09-01 17:43:53 +00:00
|
|
|
loop: "{{ local_users | difference([None]) }}"
|
2018-12-14 03:30:40 +00:00
|
|
|
|
2018-12-11 05:48:37 +00:00
|
|
|
- name: Delete users that have been removed
|
2018-12-13 04:52:32 +00:00
|
|
|
tags: users_delete
|
2018-12-11 05:48:37 +00:00
|
|
|
block:
|
|
|
|
- name: Determine existing users
|
|
|
|
shell: 'grep omni /etc/group | cut -d: -f4 | tr "," "\n"'
|
|
|
|
changed_when: false
|
|
|
|
register: existing_users
|
|
|
|
|
|
|
|
- name: Coallate user names
|
|
|
|
set_fact:
|
|
|
|
user_names: "{{ user_names | default([]) + [item.name] }}"
|
2019-09-01 17:43:53 +00:00
|
|
|
loop: "{{ users }}"
|
2018-12-11 05:48:37 +00:00
|
|
|
|
|
|
|
- name: Determine removed users
|
|
|
|
set_fact:
|
2019-09-01 17:43:53 +00:00
|
|
|
removed_users: "{{ existing_users.stdout_lines | difference(local_users) | difference([None]) }}"
|
2018-12-11 05:48:37 +00:00
|
|
|
|
|
|
|
- name: Delete removed user accounts
|
|
|
|
become: true
|
|
|
|
user:
|
|
|
|
name: "{{ item }}"
|
|
|
|
state: absent
|
2019-09-01 17:43:53 +00:00
|
|
|
loop: "{{ removed_users }}"
|
2018-12-11 05:48:37 +00:00
|
|
|
|
|
|
|
- name: Grant sudo permissions
|
2018-12-13 04:52:32 +00:00
|
|
|
tags: users_sudo
|
2018-12-11 05:48:37 +00:00
|
|
|
block:
|
|
|
|
- name: Add users to sudo group on Fedora/CentOS/RHEL
|
|
|
|
when: ansible_distribution == "Fedora" or ansible_distribution == "Red Hat Enterprise Linux" or ansible_distribution == "CentOS"
|
|
|
|
become: true
|
|
|
|
user:
|
2018-12-13 05:50:43 +00:00
|
|
|
name: "{{ item }}"
|
2018-12-11 05:48:37 +00:00
|
|
|
groups: wheel
|
|
|
|
state: present
|
2019-09-01 17:43:53 +00:00
|
|
|
loop: "{{ local_admin_users | difference([None]) }}"
|
2018-12-11 05:48:37 +00:00
|
|
|
|
|
|
|
- name: Disable sudo password for ansible
|
|
|
|
become: true
|
|
|
|
lineinfile:
|
|
|
|
create: yes
|
2018-12-13 04:52:32 +00:00
|
|
|
path: /etc/sudoers.d/30-ansible
|
2018-12-11 05:48:37 +00:00
|
|
|
line: "ansible ALL=(ALL) NOPASSWD:ALL"
|
|
|
|
mode: 0644
|
|
|
|
|
|
|
|
- name: Disable sudo password for admin users
|
|
|
|
become: true
|
|
|
|
lineinfile:
|
|
|
|
create: yes
|
2018-12-13 05:50:43 +00:00
|
|
|
path: /etc/sudoers.d/40-admin
|
2018-12-11 05:48:37 +00:00
|
|
|
line: "{{ item }} ALL=(ALL) NOPASSWD:ALL"
|
|
|
|
mode: 0644
|
2018-12-13 05:50:43 +00:00
|
|
|
state: "{{ 'absent' if disable_sudo_password|bool == false else 'present' }}"
|
2019-09-01 17:43:53 +00:00
|
|
|
loop: "{{ local_admin_users | difference([None] )}}"
|
2018-12-11 05:48:37 +00:00
|
|
|
|
|
|
|
- name: Configure GNOME
|
2018-12-13 04:52:32 +00:00
|
|
|
tags: users_gnome
|
2018-12-13 05:50:43 +00:00
|
|
|
when: ansible_distribution == "Fedora" and disable_gnome_user_list|bool == true
|
2019-09-01 17:43:53 +00:00
|
|
|
become: true
|
2018-12-11 05:48:37 +00:00
|
|
|
block:
|
|
|
|
- name: Configure GDM profile
|
|
|
|
blockinfile:
|
|
|
|
path: /etc/ssh/sshd_config
|
|
|
|
block: |
|
|
|
|
user-db:user
|
|
|
|
system-db:gdm
|
|
|
|
file-db:/usr/share/gdm/greeter-dconf-defaults
|
|
|
|
- name: Configure GDM keyfile
|
|
|
|
blockinfile:
|
2019-03-03 18:23:15 +00:00
|
|
|
create: true
|
2018-12-11 05:48:37 +00:00
|
|
|
path: /etc/dconf/db/gdm.d/00-login-screen
|
|
|
|
block: |
|
|
|
|
[org/gnome/login-screen]
|
|
|
|
# Do not show the user list
|
|
|
|
disable-user-list=true
|
|
|
|
- name: Delete existing user database
|
2018-12-13 04:52:32 +00:00
|
|
|
file:
|
|
|
|
path: /var/lib/gdm/.config/dconf/user
|
|
|
|
state: absent
|
2018-12-11 05:48:37 +00:00
|
|
|
- name: Restart dconf database
|
|
|
|
shell: dconf update
|
2018-12-13 04:52:32 +00:00
|
|
|
|
|
|
|
- name: Install public keys
|
|
|
|
tags: users_keys
|
|
|
|
become: true
|
|
|
|
block:
|
|
|
|
- name: Ensure SSH directory exists
|
|
|
|
file:
|
|
|
|
state: directory
|
|
|
|
path: /home/{{ item.name }}/.ssh
|
2019-09-01 17:43:53 +00:00
|
|
|
loop: "{{ local_users | difference([None]) }}"
|
2018-12-13 04:52:32 +00:00
|
|
|
- name: Put keys on remote
|
2019-09-01 17:54:49 +00:00
|
|
|
when: item.keys != []
|
2018-12-13 04:52:32 +00:00
|
|
|
authorized_key:
|
|
|
|
user: "{{ item.name }}"
|
2019-09-01 17:54:49 +00:00
|
|
|
key: "{{ item.sshkeys | join('\n') }}"
|
2018-12-13 04:52:32 +00:00
|
|
|
state: present
|
|
|
|
exclusive: yes
|
2019-09-01 17:43:53 +00:00
|
|
|
loop: "{{ local_users | difference([None]) }}"
|
2018-12-13 04:52:32 +00:00
|
|
|
|
|
|
|
- name: Ensure proper ownership of user home directories
|
|
|
|
become: true
|
|
|
|
file:
|
|
|
|
group: "{{ item.name }}"
|
|
|
|
owner: "{{ item.name }}"
|
|
|
|
path: /home/{{ item.name }}
|
|
|
|
recurse: yes
|
|
|
|
state: directory
|
2019-09-01 17:43:53 +00:00
|
|
|
loop: "{{ local_users | difference([None]) }}"
|
2018-12-31 03:54:33 +00:00
|
|
|
|
|
|
|
- hosts: all
|
|
|
|
name: Disable SSH password authentication
|
2019-09-01 17:54:49 +00:00
|
|
|
tags:
|
|
|
|
- always
|
2018-12-31 03:54:33 +00:00
|
|
|
tasks:
|
|
|
|
- import_tasks: tasks/sshd/disable-password-auth.yml
|
|
|
|
when: enable_ssh_password_auth|bool == false
|