109 lines
2.8 KiB
YAML
109 lines
2.8 KiB
YAML
- name: Install useful software
|
|
ansible.builtin.apt:
|
|
name: "{{ packages }}"
|
|
state: present
|
|
update_cache: true
|
|
|
|
- name: Install GPG
|
|
ansible.builtin.apt:
|
|
name: gpg
|
|
state: present
|
|
|
|
- name: Check for existing GPG keys
|
|
ansible.builtin.command: "gpg --list-keys {{ item.id }} 2>/dev/null"
|
|
register: gpg_check
|
|
loop: "{{ root_gpgkeys }}"
|
|
failed_when: false
|
|
changed_when: false
|
|
when: root_gpgkeys is defined
|
|
|
|
- name: Import GPG keys
|
|
ansible.builtin.command:
|
|
"gpg --keyserver {{ item.item.server | default('keys.openpgp.org') }} --recv-key {{ item.item.id }}"
|
|
register: gpg_check_import
|
|
loop: "{{ gpg_check.results }}"
|
|
loop_control:
|
|
label: "{{ item.item }}"
|
|
changed_when: false
|
|
when: root_gpgkeys is defined and item.rc != 0
|
|
|
|
- name: Check GPG key imports
|
|
ansible.builtin.fail:
|
|
msg: "{{ item.stderr }}"
|
|
loop: "{{ gpg_check_import.results }}"
|
|
loop_control:
|
|
label: "{{ item.item.item }}"
|
|
when: root_gpgkeys is defined and (not item.skipped | default(false)) and ('imported' not in item.stderr)
|
|
|
|
- name: Install NTPsec
|
|
ansible.builtin.apt:
|
|
name: ntpsec
|
|
state: present
|
|
|
|
- name: Install locales
|
|
ansible.builtin.apt:
|
|
name: locales
|
|
state: present
|
|
|
|
- name: Generate locale
|
|
community.general.locale_gen:
|
|
name: "{{ locale_default }}"
|
|
state: present
|
|
notify: reconfigure_locales
|
|
|
|
- name: Set the default locale
|
|
ansible.builtin.lineinfile:
|
|
path: /etc/default/locale
|
|
regexp: "^LANG="
|
|
line: "LANG={{ locale_default }}"
|
|
|
|
- name: Manage root authorized_keys
|
|
ansible.builtin.template:
|
|
src: authorized_keys.j2
|
|
dest: /root/.ssh/authorized_keys
|
|
mode: "400"
|
|
when: authorized_keys is defined
|
|
|
|
- name: Create system user groups
|
|
ansible.builtin.group:
|
|
name: "{{ item.key }}"
|
|
gid: "{{ item.value.gid }}"
|
|
state: present
|
|
loop: "{{ users | dict2items }}"
|
|
loop_control:
|
|
label: "{{ item.key }}"
|
|
when: users is defined
|
|
|
|
- name: Create system users
|
|
ansible.builtin.user:
|
|
name: "{{ item.key }}"
|
|
state: present
|
|
uid: "{{ item.value.uid }}"
|
|
group: "{{ item.value.gid }}"
|
|
shell: "{{ item.value.shell | default('/bin/bash') }}"
|
|
create_home: "{{ item.value.home | default(false) }}"
|
|
system: "{{ item.value.system | default(false) }}"
|
|
loop: "{{ users | dict2items }}"
|
|
loop_control:
|
|
label: "{{ item.key }}"
|
|
when: users is defined
|
|
|
|
- name: Set authorized_keys for system users
|
|
ansible.posix.authorized_key:
|
|
user: "{{ item.key }}"
|
|
key: "{{ item.value.key }}"
|
|
state: present
|
|
loop: "{{ users | dict2items }}"
|
|
loop_control:
|
|
label: "{{ item.key }}"
|
|
when: users is defined and item.value.key is defined
|
|
|
|
- name: Manage filesystem mounts
|
|
ansible.posix.mount:
|
|
path: "{{ item.path }}"
|
|
src: "UUID={{ item.uuid }}"
|
|
fstype: "{{ item.fstype }}"
|
|
state: mounted
|
|
loop: "{{ mounts }}"
|
|
when: mounts is defined
|