126 lines
4.1 KiB
YAML
126 lines
4.1 KiB
YAML
---
|
|
- import_playbook: dependencies.yml
|
|
|
|
- hosts: all
|
|
name: Update local user accounts and access controls
|
|
tasks:
|
|
- import_tasks: tasks/users-preprocessing.yml
|
|
|
|
- name: Create local user accounts
|
|
tags: users_create
|
|
become: true
|
|
block:
|
|
- name: Create groups
|
|
group:
|
|
name: "{{ item }}"
|
|
state: present
|
|
loop: "{{ targets + ['omni'] }}"
|
|
|
|
- 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
|
|
generate_ssh_key: "{{ 'yes' if generate_keys|bool == true else 'no' }}"
|
|
ssh_key_comment: "{{ item.name }}@{{ inventory_hostname }}"
|
|
ssh_key_bits: 4096
|
|
ssh_key_type: ed25519
|
|
password: "{{ item.password }}"
|
|
loop: "{{ local_users | difference([None]) }}"
|
|
|
|
- name: Delete users that have been removed
|
|
tags: users_delete
|
|
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] }}"
|
|
loop: "{{ users }}"
|
|
|
|
- name: Determine removed users
|
|
set_fact:
|
|
removed_users: "{{ existing_users.stdout_lines | difference(local_users) | difference([None]) }}"
|
|
|
|
- name: Delete removed user accounts
|
|
become: true
|
|
user:
|
|
name: "{{ item }}"
|
|
state: absent
|
|
loop: "{{ removed_users }}"
|
|
|
|
- name: Grant sudo permissions
|
|
tags: users_sudo
|
|
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:
|
|
name: "{{ item }}"
|
|
groups: wheel
|
|
state: present
|
|
loop: "{{ local_admin_users | difference([None]) }}"
|
|
|
|
- name: Disable sudo password for ansible
|
|
become: true
|
|
lineinfile:
|
|
create: yes
|
|
path: /etc/sudoers.d/30-ansible
|
|
line: "ansible ALL=(ALL) NOPASSWD:ALL"
|
|
mode: 0644
|
|
|
|
- name: Disable sudo password for admin users
|
|
become: true
|
|
lineinfile:
|
|
create: yes
|
|
path: /etc/sudoers.d/40-admin
|
|
line: "{{ item }} ALL=(ALL) NOPASSWD:ALL"
|
|
mode: 0644
|
|
state: "{{ 'absent' if disable_sudo_password|bool == false else 'present' }}"
|
|
loop: "{{ local_admin_users | difference([None] )}}"
|
|
|
|
- name: Configure GNOME
|
|
tags: users_gnome
|
|
when: ansible_distribution == "Fedora" and disable_gnome_user_list|bool == true
|
|
become: true
|
|
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:
|
|
create: true
|
|
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
|
|
file:
|
|
path: /var/lib/gdm/.config/dconf/user
|
|
state: absent
|
|
- name: Restart dconf database
|
|
shell: dconf update
|
|
|
|
- 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
|
|
loop: "{{ local_users | difference([None]) }}"
|
|
|
|
- import_playbook: deploy-sshkeys.yml
|