Add playbook for updating existing settings
This commit is contained in:
parent
d45facb76d
commit
091c5a78a6
@ -49,6 +49,7 @@
|
|||||||
requirements: "{{ skylab_ansible_venv }}/requirements.txt"
|
requirements: "{{ skylab_ansible_venv }}/requirements.txt"
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
|
|
||||||
- name: Configure common server settings
|
- name: Configure common server settings
|
||||||
hosts: all
|
hosts: all
|
||||||
vars_files:
|
vars_files:
|
||||||
@ -101,6 +102,7 @@
|
|||||||
name: "{{ skylab_packages_global + skylab_packages_rocky }}"
|
name: "{{ skylab_packages_global + skylab_packages_rocky }}"
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
|
|
||||||
- name: Configure SSH
|
- name: Configure SSH
|
||||||
hosts: all
|
hosts: all
|
||||||
handlers:
|
handlers:
|
||||||
@ -162,3 +164,6 @@
|
|||||||
src: motd.j2
|
src: motd.j2
|
||||||
dest: /etc/motd
|
dest: /etc/motd
|
||||||
mode: 0644
|
mode: 0644
|
||||||
|
|
||||||
|
|
||||||
|
- import_playbook: update.yaml
|
||||||
|
161
playbooks/update.yaml
Normal file
161
playbooks/update.yaml
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
---
|
||||||
|
- name: Update system
|
||||||
|
hosts: all
|
||||||
|
tags:
|
||||||
|
- packages
|
||||||
|
vars_files:
|
||||||
|
- vars/packages.yaml
|
||||||
|
tasks:
|
||||||
|
- name: Update system packages via DNF
|
||||||
|
when: ansible_distribution == "Rocky"
|
||||||
|
become: true
|
||||||
|
ansible.builtin.dnf:
|
||||||
|
name: "*"
|
||||||
|
state: latest
|
||||||
|
|
||||||
|
- name: Update unix accounts
|
||||||
|
hosts: all
|
||||||
|
tags:
|
||||||
|
- accounts
|
||||||
|
- access
|
||||||
|
vars_files:
|
||||||
|
- vars/access.yaml
|
||||||
|
- vars/sshkeys.yaml
|
||||||
|
tasks:
|
||||||
|
- name: Create management groups
|
||||||
|
become: true
|
||||||
|
ansible.builtin.group:
|
||||||
|
name: "{{ item.name }}"
|
||||||
|
gid: "{{ item.gid }}"
|
||||||
|
state: present
|
||||||
|
loop:
|
||||||
|
- "{{ skylab_group }}"
|
||||||
|
- "{{ skylab_group_admin }}"
|
||||||
|
- "{{ skylab_group_automation }}"
|
||||||
|
|
||||||
|
- name: Determine existing skylab users
|
||||||
|
changed_when: false
|
||||||
|
ansible.builtin.shell:
|
||||||
|
cmd: 'grep {{ skylab_group.name }} /etc/group | cut --delimiter : --fields 4 | tr "," "\n"'
|
||||||
|
register: _existing_skylab_accounts
|
||||||
|
|
||||||
|
- name: Delete removed user accounts
|
||||||
|
become: true
|
||||||
|
when: item not in (skylab_accounts | items2dict(key_name='name', value_name='uid'))
|
||||||
|
ansible.builtin.user:
|
||||||
|
name: "{{ item }}"
|
||||||
|
state: absent
|
||||||
|
loop: "{{ _existing_skylab_accounts.stdout_lines }}"
|
||||||
|
|
||||||
|
- name: Delete removed user groups
|
||||||
|
become: true
|
||||||
|
when: item not in (skylab_accounts | items2dict(key_name='name', value_name='uid'))
|
||||||
|
ansible.builtin.group:
|
||||||
|
name: "{{ item }}"
|
||||||
|
state: absent
|
||||||
|
loop: "{{ _existing_skylab_accounts.stdout_lines }}"
|
||||||
|
|
||||||
|
- name: Delete removed user home directories
|
||||||
|
become: true
|
||||||
|
when: item not in (skylab_accounts | items2dict(key_name='name', value_name='uid'))
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "/home/{{ item }}"
|
||||||
|
state: absent
|
||||||
|
loop: "{{ _existing_skylab_accounts.stdout_lines }}"
|
||||||
|
|
||||||
|
- name: Create account groups
|
||||||
|
when: item.targets | intersect(skylab_targets)
|
||||||
|
become: true
|
||||||
|
ansible.builtin.group:
|
||||||
|
name: "{{ item.name }}"
|
||||||
|
gid: "{{ item.uid }}"
|
||||||
|
state: present
|
||||||
|
loop: "{{ skylab_accounts }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.uid }},{{ item.name }}"
|
||||||
|
|
||||||
|
- name: Determine account groups
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
_determined_member_groups: "{{ _determined_member_groups | default({}) | combine({item.name: [
|
||||||
|
skylab_group.name,
|
||||||
|
'wheel' if (item.admin | default(false) and ansible_distribution == 'Rocky') else '',
|
||||||
|
'sudo' if (item.admin | default(false) and ansible_os_family == 'Debian') else '',
|
||||||
|
skylab_group_admin.name if item.admin | default(false) else '',
|
||||||
|
skylab_group_automation.name if item.service | default(false) else '',
|
||||||
|
]}) }}"
|
||||||
|
loop: "{{ skylab_accounts }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.uid }},{{ item.name }}"
|
||||||
|
|
||||||
|
- name: Create accounts
|
||||||
|
when: item.targets | intersect(skylab_targets)
|
||||||
|
become: true
|
||||||
|
ansible.builtin.user:
|
||||||
|
name: "{{ item.name }}"
|
||||||
|
state: present
|
||||||
|
uid: "{{ item.uid }}"
|
||||||
|
group: "{{ item.name }}"
|
||||||
|
groups: "{{ _determined_member_groups[item.name] }}"
|
||||||
|
comment: "{{ item.fullname | default('') }}"
|
||||||
|
system: "{{ item.service | default(false) }}"
|
||||||
|
generate_ssh_key: false
|
||||||
|
password: "{{ item.password }}"
|
||||||
|
loop: "{{ skylab_accounts }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.uid }},{{ item.name }}"
|
||||||
|
|
||||||
|
- name: Ensure proper ownership of user home directories
|
||||||
|
become: true
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /home/{{ item.name }}
|
||||||
|
state: directory
|
||||||
|
group: "{{ item.name }}"
|
||||||
|
owner: "{{ item.name }}"
|
||||||
|
mode: 0700
|
||||||
|
loop: "{{ skylab_accounts }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.uid }},{{ item.name }}"
|
||||||
|
|
||||||
|
- name: Enforce root password
|
||||||
|
become: true
|
||||||
|
ansible.builtin.user:
|
||||||
|
name: root
|
||||||
|
password: "{{ skylab_root_password }}"
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: Create SSH directory
|
||||||
|
become: true
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /home/{{ item.name }}/.ssh
|
||||||
|
owner: "{{ item.name }}"
|
||||||
|
group: "{{ item.name }}"
|
||||||
|
state: directory
|
||||||
|
mode: 0700
|
||||||
|
loop: "{{ skylab_accounts }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.uid }},{{ item.name }}"
|
||||||
|
|
||||||
|
- name: Update authorized keys
|
||||||
|
become: true
|
||||||
|
when: item.targets | intersect(skylab_targets)
|
||||||
|
ansible.builtin.authorized_key:
|
||||||
|
user: "{{ item.name }}"
|
||||||
|
key: "{{ skylab_ssh_keys[item.name] | join('\n') }}"
|
||||||
|
state: present
|
||||||
|
exclusive: true
|
||||||
|
loop: "{{ skylab_accounts }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.uid }},{{ item.name }}"
|
||||||
|
|
||||||
|
- name: Enforce ownership of authorized keys
|
||||||
|
become: true
|
||||||
|
when: item.targets | intersect(skylab_targets)
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /home/{{ item.name }}/.ssh/authorized_keys
|
||||||
|
state: file
|
||||||
|
owner: "{{ item.name }}"
|
||||||
|
group: "{{ item.name }}"
|
||||||
|
mode: 0400
|
||||||
|
loop: "{{ skylab_accounts }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.uid }},{{ item.name }}"
|
1
playbooks/vars
Symbolic link
1
playbooks/vars
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../vars/
|
@ -5,6 +5,7 @@ skylab_accounts:
|
|||||||
fullname: Ethan N. Paul
|
fullname: Ethan N. Paul
|
||||||
targets: [cloud]
|
targets: [cloud]
|
||||||
admin: true
|
admin: true
|
||||||
|
password: $y$j9T$cWkd9aGj4sNepyJm5NVZl0$yBhFy3cN3syM8r4doGYnsLZhsaTLQVoDIBs2kkXtxY2
|
||||||
|
|
||||||
- name: ansible
|
- name: ansible
|
||||||
uid: 1400
|
uid: 1400
|
||||||
@ -24,3 +25,5 @@ skylab_group_admin:
|
|||||||
skylab_group_automation:
|
skylab_group_automation:
|
||||||
name: skylab_auto
|
name: skylab_auto
|
||||||
gid: 1202
|
gid: 1202
|
||||||
|
|
||||||
|
skylab_root_password: $y$j9T$vcNKa2vbTBQLGsU7QZfkM0$4.gw4YqknZJSZJ/uRKFI36G8JtK/MJPsxFdTTmzQoL6
|
||||||
|
9
vars/sshkeys.yaml
Normal file
9
vars/sshkeys.yaml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
skylab_ssh_keys:
|
||||||
|
enpaul:
|
||||||
|
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDi9rWRC15og/+3Jc3AMHOrlIc2BHaAX9PLbklz3qfFtSOp9bIScMcH5ZR6lyVSgP8RCEjI5HuZejDUJTXUQYfvEJeno//vmxn9Vw66lpMz/FSJ3JcDbjDVI1pe3A8mTOAS+AoVOEzCUOJVZJvdI272Hgf+QRBu+ONQ12u+2XYdVfLFDe7mAG+vEJRBatwb8B7Al+/LUpIrCuPm9PzMBtCMFjWGaqQgnyJYRSPIGxz9231XIjwhHLOQG1R0jLGuS37X+J49Y5JYDaHf9q9KH76GjdO2rOq6aGvwN93Y4Z+D2hMOklhD0Ez/ZE+I3ZUPV0e5pF28gsA6L7gTeqmSGpQaKdwjCUoU12VM70OVxng5p2+7DIc0k2np7rnvd4zybgn9OMM+TIO5M3c6ocDuNsEmRgfS3V99X5oh9qNy35UdBXV08j0wFoUo1KcyGwyNBYzKzvkkvtgJezVKmqSPKeBjMgMX4UsJsMn27Zosk0ZgoUwLFPO9Pg7uShncwgsTnvYDR1ws53PV832gc7A85ud/dC9Fjn6jBsMQaCFbiZktc5J8mv3cugQHQesbq8Y2aNVRu+ECb+KUvAEdPacWdBOkk0IvZ4PvLrAs2xehF6FYVqKVtPlJMaUAAwj9vVx7Nl2HnsSRIrCgxsMOTOhbbp/3NrvM8r6K7zKBzXg2TNgQeQ== enpaul@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