2020-07-10 01:54:15 +00:00
|
|
|
- name: Install useful software
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.builtin.apt:
|
2020-08-15 22:14:45 +00:00
|
|
|
name: "{{ packages }}"
|
2020-07-10 01:54:15 +00:00
|
|
|
state: present
|
2020-09-21 21:41:32 +00:00
|
|
|
update_cache: true
|
2020-07-29 05:09:46 +00:00
|
|
|
|
2023-10-10 03:47:49 +00:00
|
|
|
- name: Install GPG
|
|
|
|
ansible.builtin.apt:
|
|
|
|
name: gpg
|
|
|
|
state: present
|
|
|
|
|
2023-10-19 06:56:36 +00:00
|
|
|
- name: Check for existing GPG keys
|
2023-10-21 01:30:25 +00:00
|
|
|
ansible.builtin.command: "gpg --list-keys {{ item.id }} 2>/dev/null"
|
2023-10-19 06:56:36 +00:00
|
|
|
register: gpg_check
|
|
|
|
loop: "{{ root_gpgkeys }}"
|
|
|
|
failed_when: false
|
|
|
|
changed_when: false
|
|
|
|
when: root_gpgkeys is defined
|
|
|
|
|
|
|
|
- name: Import GPG keys
|
2023-10-21 01:30:25 +00:00
|
|
|
ansible.builtin.command:
|
|
|
|
"gpg --keyserver {{ item.item.server | default('keys.openpgp.org') }} --recv-key {{ item.item.id }}"
|
2023-10-19 17:37:35 +00:00
|
|
|
register: gpg_check_import
|
2023-10-19 18:09:10 +00:00
|
|
|
loop: "{{ gpg_check.results }}"
|
2023-10-19 17:37:35 +00:00
|
|
|
loop_control:
|
2023-10-19 20:36:05 +00:00
|
|
|
label: "{{ item.item }}"
|
2023-10-21 01:30:25 +00:00
|
|
|
changed_when: false
|
2023-10-19 18:09:10 +00:00
|
|
|
when: root_gpgkeys is defined and item.rc != 0
|
2023-10-19 17:37:35 +00:00
|
|
|
|
|
|
|
- name: Check GPG key imports
|
2023-10-21 01:30:25 +00:00
|
|
|
ansible.builtin.fail:
|
2023-10-19 17:37:35 +00:00
|
|
|
msg: "{{ item.stderr }}"
|
|
|
|
loop: "{{ gpg_check_import.results }}"
|
|
|
|
loop_control:
|
2023-10-19 20:36:05 +00:00
|
|
|
label: "{{ item.item.item }}"
|
2023-10-21 01:30:25 +00:00
|
|
|
when: root_gpgkeys is defined and (not item.skipped | default(false)) and ('imported' not in item.stderr)
|
2023-10-19 06:56:36 +00:00
|
|
|
|
2023-10-19 05:27:31 +00:00
|
|
|
- name: Install NTPsec
|
|
|
|
ansible.builtin.apt:
|
|
|
|
name: ntpsec
|
|
|
|
state: present
|
|
|
|
|
2023-10-18 20:32:09 +00:00
|
|
|
- name: Install locales
|
|
|
|
ansible.builtin.apt:
|
|
|
|
name: locales
|
|
|
|
state: present
|
|
|
|
|
|
|
|
- name: Generate locale
|
|
|
|
community.general.locale_gen:
|
|
|
|
name: "{{ locale_default }}"
|
|
|
|
state: present
|
2023-10-21 01:30:25 +00:00
|
|
|
notify: reconfigure_locales
|
2023-10-18 20:32:09 +00:00
|
|
|
|
|
|
|
- name: Set the default locale
|
|
|
|
ansible.builtin.lineinfile:
|
|
|
|
path: /etc/default/locale
|
|
|
|
regexp: "^LANG="
|
|
|
|
line: "LANG={{ locale_default }}"
|
|
|
|
|
2020-07-29 05:09:46 +00:00
|
|
|
- name: Manage root authorized_keys
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.builtin.template:
|
2020-07-29 05:09:46 +00:00
|
|
|
src: authorized_keys.j2
|
|
|
|
dest: /root/.ssh/authorized_keys
|
2023-10-21 01:30:25 +00:00
|
|
|
mode: "400"
|
2020-07-29 05:09:46 +00:00
|
|
|
when: authorized_keys is defined
|
2020-09-01 16:56:27 +00:00
|
|
|
|
2023-10-20 19:41:44 +00:00
|
|
|
- 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
|
|
|
|
|
2023-06-07 06:12:17 +00:00
|
|
|
- name: Create system users
|
|
|
|
ansible.builtin.user:
|
2023-10-20 19:41:44 +00:00
|
|
|
name: "{{ item.key }}"
|
2023-06-07 06:12:17 +00:00
|
|
|
state: present
|
2023-10-20 19:41:44 +00:00
|
|
|
uid: "{{ item.value.uid }}"
|
|
|
|
group: "{{ item.value.gid }}"
|
|
|
|
shell: "{{ item.value.shell | default('/bin/bash') }}"
|
|
|
|
create_home: "{{ item.value.home | default(false) }}"
|
2023-10-21 01:30:25 +00:00
|
|
|
system: "{{ item.value.system | default(false) }}"
|
2023-10-20 19:41:44 +00:00
|
|
|
loop: "{{ users | dict2items }}"
|
|
|
|
loop_control:
|
|
|
|
label: "{{ item.key }}"
|
2023-06-07 06:12:17 +00:00
|
|
|
when: users is defined
|
|
|
|
|
|
|
|
- name: Set authorized_keys for system users
|
|
|
|
ansible.posix.authorized_key:
|
|
|
|
user: "{{ item.key }}"
|
|
|
|
key: "{{ item.value.key }}"
|
|
|
|
state: present
|
2023-10-20 19:41:44 +00:00
|
|
|
loop: "{{ users | dict2items }}"
|
|
|
|
loop_control:
|
|
|
|
label: "{{ item.key }}"
|
2023-06-07 06:12:17 +00:00
|
|
|
when: users is defined and item.value.key is defined
|
|
|
|
|
2020-09-01 16:56:27 +00:00
|
|
|
- name: Manage filesystem mounts
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.posix.mount:
|
2020-09-01 16:56:27 +00:00
|
|
|
path: "{{ item.path }}"
|
|
|
|
src: "UUID={{ item.uuid }}"
|
|
|
|
fstype: "{{ item.fstype }}"
|
|
|
|
state: mounted
|
|
|
|
loop: "{{ mounts }}"
|
|
|
|
when: mounts is defined
|