Refactor Ansible tasks in basic.yml to use module prefixes and improve variable naming consistency

This commit is contained in:
2026-07-20 22:57:13 +02:00
parent ba1d600cd8
commit bc330beebf
+61 -40
View File
@@ -4,19 +4,20 @@
ansible.builtin.apt: ansible.builtin.apt:
name: util-linux-extra name: util-linux-extra
state: present state: present
update_cache: yes update_cache: true
when: when:
- ansible_facts['os_family'] == 'Debian' - ansible_facts['os_family'] == 'Debian'
- ansible_facts['distribution_major_version'] | int >= 11 - ansible_facts['distribution_major_version'] | int >= 11
- name: (basic.yml) Ensure timezone is is correct - name: (basic.yml) Ensure timezone is is correct
timezone: name={{ time_zone }} community.general.timezone:
name: "{{ time_zone }}"
tags: tags:
- timezone - timezone
- name: (basic.yml) Ensure locales are present - name: (basic.yml) Ensure locales are present
locale_gen: community.general.locale_gen:
name: "{{ item }}" name: "{{ item }}"
state: present state: present
with_items: "{{ locales }}" with_items: "{{ locales }}"
@@ -26,7 +27,7 @@
- locales - locales
- name: (basic.yml) Create a symbolic link /bin/sh -> bash - name: (basic.yml) Create a symbolic link /bin/sh -> bash
file: ansible.builtin.file:
src: bash src: bash
dest: /bin/sh dest: /bin/sh
owner: root owner: root
@@ -41,13 +42,13 @@
# ---------- # ----------
- name: (basic.yml) Ensure directory '/etc/security/limits.d' exists - name: (basic.yml) Ensure directory '/etc/security/limits.d' exists
file: ansible.builtin.file:
path: /etc/security/limits.d path: /etc/security/limits.d
state: directory state: directory
mode: 0755 mode: '0755'
group: root group: root
owner: root owner: root
when: when:
- inventory_hostname not in groups['lxc_guest'] or inventory_hostname in groups['lxc_host'] or inventory_hostname in groups['oopen_office_server'] - inventory_hostname not in groups['lxc_guest'] or inventory_hostname in groups['lxc_host'] or inventory_hostname in groups['oopen_office_server']
- copy_plain_files_security_limits is defined - copy_plain_files_security_limits is defined
- copy_plain_files_security_limits|length > 0 - copy_plain_files_security_limits|length > 0
@@ -55,7 +56,7 @@
- systemd-config - systemd-config
- name: (basic.yml) Ensure files /etc/security/limits.d/*.conf exists - name: (basic.yml) Ensure files /etc/security/limits.d/*.conf exists
copy: ansible.builtin.copy:
src: '{{ item.src_path }}' src: '{{ item.src_path }}'
dest: '{{ item.dest_path }}' dest: '{{ item.dest_path }}'
owner: root owner: root
@@ -64,7 +65,7 @@
loop: "{{ copy_plain_files_security_limits }}" loop: "{{ copy_plain_files_security_limits }}"
loop_control: loop_control:
label: 'dest: {{ item.name }}' label: 'dest: {{ item.name }}'
when: when:
- inventory_hostname not in groups['lxc_guest'] or inventory_hostname in groups['lxc_host'] or inventory_hostname in groups['oopen_office_server'] - inventory_hostname not in groups['lxc_guest'] or inventory_hostname in groups['lxc_host'] or inventory_hostname in groups['oopen_office_server']
- copy_plain_files_security_limits is defined - copy_plain_files_security_limits is defined
- copy_plain_files_security_limits|length > 0 - copy_plain_files_security_limits|length > 0
@@ -77,21 +78,25 @@
# ---------- # ----------
- name: (basic.yml) Ensure directory '/etc/systemd/system.conf.d' exists - name: (basic.yml) Ensure directory '/etc/systemd/system.conf.d' exists
file: ansible.builtin.file:
path: /etc/systemd/system.conf.d path: /etc/systemd/system.conf.d
state: directory state: directory
mode: 0755 mode: '0755'
group: root group: root
owner: root owner: root
when: when:
- inventory_hostname not in groups['lxc_guest'] or inventory_hostname in groups['lxc_host'] or inventory_hostname in groups['oopen_office_server'] or inventory_hostname in groups['jitsi_meet_server'] - >-
inventory_hostname not in groups['lxc_guest'] or
inventory_hostname in groups['lxc_host'] or
inventory_hostname in groups['oopen_office_server'] or
inventory_hostname in groups['jitsi_meet_server']
- copy_plain_files_systemd is defined - copy_plain_files_systemd is defined
- copy_plain_files_systemd|length > 0 - copy_plain_files_systemd|length > 0
tags: tags:
- systemd-config - systemd-config
- name: (basic.yml) Ensure files /etc/systemd/system.conf.d/*.conf exists - name: (basic.yml) Ensure files /etc/systemd/system.conf.d/*.conf exists
copy: ansible.builtin.copy:
src: '{{ item.src_path }}' src: '{{ item.src_path }}'
dest: '{{ item.dest_path }}' dest: '{{ item.dest_path }}'
owner: root owner: root
@@ -100,18 +105,22 @@
loop: "{{ copy_plain_files_systemd }}" loop: "{{ copy_plain_files_systemd }}"
loop_control: loop_control:
label: 'dest: {{ item.name }}' label: 'dest: {{ item.name }}'
when: when:
- inventory_hostname not in groups['lxc_guest'] or inventory_hostname in groups['lxc_host'] or inventory_hostname in groups['oopen_office_server'] or inventory_hostname in groups['jitsi_meet_server'] - >-
inventory_hostname not in groups['lxc_guest'] or
inventory_hostname in groups['lxc_host'] or
inventory_hostname in groups['oopen_office_server'] or
inventory_hostname in groups['jitsi_meet_server']
- copy_plain_files_systemd is defined - copy_plain_files_systemd is defined
- copy_plain_files_systemd|length > 0 - copy_plain_files_systemd|length > 0
tags: tags:
- systemd-config - systemd-config
- name: (basic.yml) Ensure directory '/etc/systemd/journald.conf.d' exists - name: (basic.yml) Ensure directory '/etc/systemd/journald.conf.d' exists
file: ansible.builtin.file:
path: /etc/systemd/journald.conf.d path: /etc/systemd/journald.conf.d
state: directory state: directory
mode: 0755 mode: '0755'
group: root group: root
owner: root owner: root
when: when:
@@ -121,7 +130,7 @@
- systemd-config - systemd-config
- name: (basic.yml) Ensure files /etc/systemd/journald.conf.d/*.conf exists - name: (basic.yml) Ensure files /etc/systemd/journald.conf.d/*.conf exists
copy: ansible.builtin.copy:
src: '{{ item.src_path }}' src: '{{ item.src_path }}'
dest: '{{ item.dest_path }}' dest: '{{ item.dest_path }}'
owner: root owner: root
@@ -143,13 +152,13 @@
# ---------- # ----------
- name: (basic.yml) Ensure directory '/etc/sysctl.d' exists - name: (basic.yml) Ensure directory '/etc/sysctl.d' exists
file: ansible.builtin.file:
path: etc/sysctl.d path: etc/sysctl.d
state: directory state: directory
mode: 0755 mode: '0755'
group: root group: root
owner: root owner: root
when: when:
- inventory_hostname not in groups['lxc_guest'] or inventory_hostname in groups['lxc_host'] or inventory_hostname in groups['oopen_office_server'] - inventory_hostname not in groups['lxc_guest'] or inventory_hostname in groups['lxc_host'] or inventory_hostname in groups['oopen_office_server']
- copy_plain_files_sysctl is defined - copy_plain_files_sysctl is defined
- copy_plain_files_sysctl|length > 0 - copy_plain_files_sysctl|length > 0
@@ -157,7 +166,7 @@
- systctl-config - systctl-config
- name: (basic.yml) Ensure files /etc/sysctl.d/*.conf exists - name: (basic.yml) Ensure files /etc/sysctl.d/*.conf exists
copy: ansible.builtin.copy:
src: '{{ item.src_path }}' src: '{{ item.src_path }}'
dest: '{{ item.dest_path }}' dest: '{{ item.dest_path }}'
owner: root owner: root
@@ -166,7 +175,7 @@
loop: "{{ copy_plain_files_sysctl }}" loop: "{{ copy_plain_files_sysctl }}"
loop_control: loop_control:
label: 'dest: {{ item.name }}' label: 'dest: {{ item.name }}'
when: when:
- inventory_hostname not in groups['lxc_guest'] or inventory_hostname in groups['lxc_host'] or inventory_hostname in groups['oopen_office_server'] - inventory_hostname not in groups['lxc_guest'] or inventory_hostname in groups['lxc_host'] or inventory_hostname in groups['oopen_office_server']
- copy_plain_files_sysctl is defined - copy_plain_files_sysctl is defined
- copy_plain_files_sysctl|length > 0 - copy_plain_files_sysctl|length > 0
@@ -174,7 +183,7 @@
- systctl-config - systctl-config
- name: (basic.yml) Additional Kernel Parameters (files /etc/sysctl.d/*.conf) - name: (basic.yml) Additional Kernel Parameters (files /etc/sysctl.d/*.conf)
copy: ansible.builtin.copy:
src: '{{ item.src_path }}' src: '{{ item.src_path }}'
dest: '{{ item.dest_path }}' dest: '{{ item.dest_path }}'
owner: root owner: root
@@ -183,7 +192,7 @@
loop: "{{ copy_additional_plain_files_sysctl }}" loop: "{{ copy_additional_plain_files_sysctl }}"
loop_control: loop_control:
label: 'dest: {{ item.name }}' label: 'dest: {{ item.name }}'
when: when:
- inventory_hostname not in groups['lxc_guest'] or inventory_hostname in groups['lxc_host'] or inventory_hostname in groups['oopen_office_server'] - inventory_hostname not in groups['lxc_guest'] or inventory_hostname in groups['lxc_host'] or inventory_hostname in groups['oopen_office_server']
- copy_additional_plain_files_sysctl is defined - copy_additional_plain_files_sysctl is defined
- copy_additional_plain_files_sysctl|length > 0 - copy_additional_plain_files_sysctl|length > 0
@@ -196,62 +205,74 @@
# ---------- # ----------
- name: (basic.yml) install unattended-upgrades - name: (basic.yml) install unattended-upgrades
apt: pkg=unattended-upgrades state=present ansible.builtin.apt:
pkg: unattended-upgrades
state: present
when: when:
- ansible_facts['distribution'] == "Debian" - ansible_facts['distribution'] == "Debian"
tags: tags:
- unattended-upgrades - unattended-upgrades
- name: (basic.yml) install apt-listchanges - name: (basic.yml) install apt-listchanges
apt: pkg=apt-listchanges state=present ansible.builtin.apt:
pkg: apt-listchanges
state: present
when: when:
- ansible_facts['distribution'] == "Debian" - ansible_facts['distribution'] == "Debian"
tags: tags:
- unattended-upgrades - unattended-upgrades
- name: (basic.yml) remove apticron - name: (basic.yml) remove apticron
apt: pkg=apticron state=absent ansible.builtin.apt:
pkg: apticron
state: absent
when: when:
- ansible_facts['distribution'] == "Debian" - ansible_facts['distribution'] == "Debian"
tags: tags:
- unattended-upgrades - unattended-upgrades
- name: (basic.yml) check if /etc/apt/apt.conf.d/20auto-upgrades exists - name: (basic.yml) check if /etc/apt/apt.conf.d/20auto-upgrades exists
stat: path=/etc/apt/apt.conf.d/20auto-upgrades ansible.builtin.stat:
register: ua_enabled path: /etc/apt/apt.conf.d/20auto-upgrades
register: common_ua_enabled
when: when:
- ansible_facts['distribution'] == "Debian" - ansible_facts['distribution'] == "Debian"
tags: tags:
- unattended-upgrades - unattended-upgrades
- name: (basic.yml) activate unattended upgrades - name: (basic.yml) activate unattended upgrades
shell: DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true dpkg-reconfigure -plow unattended-upgrades ansible.builtin.command:
when: cmd: dpkg-reconfigure -plow unattended-upgrades
creates: /etc/apt/apt.conf.d/20auto-upgrades
environment:
DEBIAN_FRONTEND: noninteractive
DEBCONF_NONINTERACTIVE_SEEN: 'true'
when:
- ansible_facts['distribution'] == "Debian" - ansible_facts['distribution'] == "Debian"
- ua_enabled.stat.exists == False - not common_ua_enabled.stat.exists
tags: tags:
- unattended-upgrades - unattended-upgrades
- name: (basic.yml) copy apt-listchanges.conf - name: (basic.yml) copy apt-listchanges.conf
template: ansible.builtin.template:
src: etc/apt/listchanges.conf.j2 src: etc/apt/listchanges.conf.j2
dest: /etc/apt/listchanges.conf dest: /etc/apt/listchanges.conf
owner: root owner: root
group: root group: root
mode: 0644 mode: '0644'
when: when:
- ansible_facts['distribution'] == "Debian" - ansible_facts['distribution'] == "Debian"
tags: tags:
- unattended-upgrades - unattended-upgrades
- name: (basic.yml) copy unattended-upgrades conf - name: (basic.yml) copy unattended-upgrades conf
template: ansible.builtin.template:
src: etc/apt/apt.conf.d/50unattended-upgrades.j2 src: etc/apt/apt.conf.d/50unattended-upgrades.j2
dest: /etc/apt/apt.conf.d/50unattended-upgrades dest: /etc/apt/apt.conf.d/50unattended-upgrades
backup: yes backup: true
owner: root owner: root
group: root group: root
mode: 0644 mode: '0644'
when: when:
- ansible_facts['distribution'] == "Debian" - ansible_facts['distribution'] == "Debian"
tags: tags: