homelab/roles/base/tasks/system.yml

94 lines
2.4 KiB
YAML
Raw Normal View History

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
update_cache: true
- name: Install GPG
ansible.builtin.apt:
name: gpg
state: present
2023-10-19 06:56:36 +00:00
- name: Check for existing GPG keys
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
2023-10-19 18:09:10 +00:00
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-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
fail:
msg: "{{ item.stderr }}"
loop: "{{ gpg_check_import.results }}"
loop_control:
2023-10-19 20:36:05 +00:00
label: "{{ item.item.item }}"
when: root_gpgkeys is defined and (item.skipped | default(false) == 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
- name: Install locales
ansible.builtin.apt:
name: locales
state: present
- name: Generate locale
community.general.locale_gen:
name: "{{ locale_default }}"
state: present
register: locale_gen_output
- name: Set the default locale
ansible.builtin.lineinfile:
path: /etc/default/locale
regexp: "^LANG="
line: "LANG={{ locale_default }}"
- name: Reconfigure locales
ansible.builtin.command: dpkg-reconfigure -f noninteractive locales
when: locale_gen_output.changed
- name: Manage root authorized_keys
2023-05-04 03:42:55 +00:00
ansible.builtin.template:
src: authorized_keys.j2
dest: /root/.ssh/authorized_keys
2023-05-04 05:44:18 +00:00
mode: 0400
when: authorized_keys is defined
2020-09-01 16:56:27 +00:00
- name: Create system users
ansible.builtin.user:
name: "{{ item.name }}"
state: present
shell: "{{ item.shell | default('/bin/bash') }}"
create_home: "{{ item.home | default(false) }}"
loop: "{{ users }}"
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 }}"
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