|
|
|
|
@@ -10,7 +10,8 @@
|
|
|
|
|
state: present
|
|
|
|
|
|
|
|
|
|
- name: Check for existing GPG keys
|
|
|
|
|
ansible.builtin.command: "gpg --list-keys {{ item.id }} 2>/dev/null"
|
|
|
|
|
ansible.builtin.command: >-
|
|
|
|
|
gpg --list-keys {{ item.id }} 2>/dev/null
|
|
|
|
|
register: gpg_check
|
|
|
|
|
loop: "{{ root_gpgkeys }}"
|
|
|
|
|
failed_when: false
|
|
|
|
|
@@ -19,9 +20,8 @@
|
|
|
|
|
|
|
|
|
|
- name: Import GPG keys
|
|
|
|
|
ansible.builtin.command: >-
|
|
|
|
|
gpg
|
|
|
|
|
--keyserver {{ item.item.server | default('keys.openpgp.org') }}
|
|
|
|
|
--recv-key {{ item.item.id }}
|
|
|
|
|
gpg --keyserver {{ item.item.server | default('keys.openpgp.org') }}
|
|
|
|
|
--recv-key {{ item.item.id }}
|
|
|
|
|
register: gpg_check_import
|
|
|
|
|
loop: "{{ gpg_check.results }}"
|
|
|
|
|
loop_control:
|
|
|
|
|
@@ -40,19 +40,21 @@
|
|
|
|
|
- not item.skipped | default(false)
|
|
|
|
|
- "'imported' not in item.stderr"
|
|
|
|
|
|
|
|
|
|
- name: Create /opt/scripts directories
|
|
|
|
|
- name: Create scripts directories
|
|
|
|
|
ansible.builtin.file:
|
|
|
|
|
path: "{{ item }}"
|
|
|
|
|
state: directory
|
|
|
|
|
mode: "755"
|
|
|
|
|
mode: "700"
|
|
|
|
|
owner: root
|
|
|
|
|
group: root
|
|
|
|
|
loop:
|
|
|
|
|
- /opt/scripts
|
|
|
|
|
- /opt/scripts/.keys
|
|
|
|
|
- "{{ base_scripts }}"
|
|
|
|
|
- "{{ base_scripts }}/.keys"
|
|
|
|
|
when: scripts is defined
|
|
|
|
|
|
|
|
|
|
- name: Generate OpenSSH deploy keys for script clones
|
|
|
|
|
community.crypto.openssh_keypair:
|
|
|
|
|
path: /opt/scripts/.keys/id_ed25519
|
|
|
|
|
path: "{{ base_scripts }}/.keys/id_ed25519"
|
|
|
|
|
type: ed25519
|
|
|
|
|
comment: "{{ ansible_hostname }}-deploy-key"
|
|
|
|
|
mode: "400"
|
|
|
|
|
@@ -68,13 +70,20 @@
|
|
|
|
|
- name: Clone external scripts projects
|
|
|
|
|
ansible.builtin.git:
|
|
|
|
|
repo: "{{ item.url }}"
|
|
|
|
|
dest: "/opt/scripts/{{ item.name }}"
|
|
|
|
|
dest: "{{ base_scripts }}/{{ item.name }}"
|
|
|
|
|
version: "{{ item.version }}"
|
|
|
|
|
accept_newhostkey: "{{ item.accept_newhostkey | default(false) }}"
|
|
|
|
|
gpg_allowlist: "{{ item.trusted_keys | default([]) }}"
|
|
|
|
|
verify_commit: "{{ true if (item.trusted_keys is defined and item.trusted_keys) else false }}"
|
|
|
|
|
key_file: /opt/scripts/.keys/id_ed25519
|
|
|
|
|
loop: "{{ scripts }}"
|
|
|
|
|
gpg_allowlist: >-
|
|
|
|
|
{{ (item.trusted_keys | default(scripts.trusted_keys) | default([]))
|
|
|
|
|
| map(attribute='id')
|
|
|
|
|
| list }}
|
|
|
|
|
verify_commit: >-
|
|
|
|
|
{{ true if
|
|
|
|
|
((item.trusted_keys | default(scripts.trusted_keys)) is defined
|
|
|
|
|
and (item.trusted_keys | default(scripts.trusted_keys)))
|
|
|
|
|
else false }}
|
|
|
|
|
key_file: "{{ base_scripts }}/.keys/id_ed25519"
|
|
|
|
|
loop: "{{ scripts.repos }}"
|
|
|
|
|
loop_control:
|
|
|
|
|
label: "{{ item.url }}"
|
|
|
|
|
when: scripts is defined
|
|
|
|
|
@@ -82,15 +91,30 @@
|
|
|
|
|
|
|
|
|
|
- name: Synchronize scripts
|
|
|
|
|
ansible.posix.synchronize:
|
|
|
|
|
src: "/opt/scripts/{{ item.name }}/{{ item.path }}"
|
|
|
|
|
dest: "{{ item.dest }}"
|
|
|
|
|
src: "{{ base_scripts }}/{{ item.0.name }}/{{ item.1.src }}"
|
|
|
|
|
dest: "{{ item.1.dest }}"
|
|
|
|
|
delegate_to: "{{ inventory_hostname }}"
|
|
|
|
|
loop: "{{ scripts | default([]) }}"
|
|
|
|
|
loop: "{{ scripts.repos | default([]) | subelements('scripts') }}"
|
|
|
|
|
loop_control:
|
|
|
|
|
label: "{{ item.name }}"
|
|
|
|
|
label: "{{ item.0.name }}: {{ item.1.src }}"
|
|
|
|
|
when: scripts is defined and scripts | length > 0
|
|
|
|
|
tags: scripts
|
|
|
|
|
|
|
|
|
|
- name: Deploy cron jobs
|
|
|
|
|
ansible.builtin.cron:
|
|
|
|
|
name: "{{ item.name }}"
|
|
|
|
|
job: "{{ item.job }}"
|
|
|
|
|
user: "{{ item.user | default('root') }}"
|
|
|
|
|
minute: "{{ item.minute | default('*') }}"
|
|
|
|
|
hour: "{{ item.hour | default('*') }}"
|
|
|
|
|
day: "{{ item.day | default('*') }}"
|
|
|
|
|
month: "{{ item.month | default('*') }}"
|
|
|
|
|
weekday: "{{ item.weekday | default('*') }}"
|
|
|
|
|
state: "{{ item.state | default('present') }}"
|
|
|
|
|
disabled: "{{ item.disabled | default(false) }}"
|
|
|
|
|
loop: "{{ cron }}"
|
|
|
|
|
when: cron is defined and cron | length > 0
|
|
|
|
|
|
|
|
|
|
- name: Install NTPsec
|
|
|
|
|
ansible.builtin.apt:
|
|
|
|
|
name: ntpsec
|
|
|
|
|
@@ -119,6 +143,7 @@
|
|
|
|
|
dest: /root/.ssh/authorized_keys
|
|
|
|
|
mode: "400"
|
|
|
|
|
when: authorized_keys is defined
|
|
|
|
|
tags: users
|
|
|
|
|
|
|
|
|
|
- name: Create system user groups
|
|
|
|
|
ansible.builtin.group:
|
|
|
|
|
@@ -129,6 +154,7 @@
|
|
|
|
|
loop_control:
|
|
|
|
|
label: "{{ item.key }}"
|
|
|
|
|
when: users is defined
|
|
|
|
|
tags: users
|
|
|
|
|
|
|
|
|
|
- name: Create system users
|
|
|
|
|
ansible.builtin.user:
|
|
|
|
|
@@ -145,10 +171,12 @@
|
|
|
|
|
loop_control:
|
|
|
|
|
label: "{{ item.key }}"
|
|
|
|
|
when: users is defined
|
|
|
|
|
tags: users
|
|
|
|
|
|
|
|
|
|
- name: Create Ansible's temporary remote directory for users
|
|
|
|
|
ansible.builtin.file:
|
|
|
|
|
path: "{{ item.value.homedir | default('/home/' + item.key) }}/.ansible/tmp"
|
|
|
|
|
path: >-
|
|
|
|
|
{{ item.value.homedir | default('/home/' + item.key) }}/.ansible/tmp
|
|
|
|
|
state: directory
|
|
|
|
|
mode: "700"
|
|
|
|
|
owner: "{{ item.key }}"
|
|
|
|
|
@@ -159,6 +187,7 @@
|
|
|
|
|
when:
|
|
|
|
|
- users is defined
|
|
|
|
|
- item.value.tmp | default(true)
|
|
|
|
|
tags: users
|
|
|
|
|
|
|
|
|
|
- name: Set authorized_keys for system users
|
|
|
|
|
ansible.posix.authorized_key:
|
|
|
|
|
@@ -169,6 +198,7 @@
|
|
|
|
|
loop_control:
|
|
|
|
|
label: "{{ item.key }}"
|
|
|
|
|
when: users is defined and item.value.key is defined
|
|
|
|
|
tags: users
|
|
|
|
|
|
|
|
|
|
- name: Manage filesystem mounts
|
|
|
|
|
ansible.posix.mount:
|
|
|
|
|
|