Refactor Ansible tasks and templates for improved consistency and clarity

This commit is contained in:
2026-07-31 02:24:42 +02:00
parent 81ef678904
commit 46327da2ac
52 changed files with 1679 additions and 1461 deletions
+83 -49
View File
@@ -5,11 +5,11 @@
# ---
- name: (nis-install-server.yml) Install nis common packages
package:
ansible.builtin.package:
name: "{{ item }}"
state: present
with_items: "{{ nis_common_packages }}"
register: nis_installed
register: common_nis_installed
tags:
- nis-install
- nis-install-server
@@ -20,7 +20,7 @@
src: etc/defaultdomain.j2
owner: root
group: root
mode: 644
mode: "0644"
tags:
- nis-install
- nis-install-server
@@ -31,13 +31,14 @@
src: etc/yp.conf.j2
owner: root
group: root
mode: 644
mode: "0644"
tags:
- nis-install
- nis-install-client
- name: (nis-install-server.yml) Set local host's domain name
command: domainname "{{ nis_domain }}"
ansible.builtin.command: domainname "{{ nis_domain }}"
changed_when: false
tags:
- nis-install
- nis-install-server
@@ -51,9 +52,9 @@
# ---
- name: (nis-install-server.yml) Check if file '/etc/pam.d/common-password' exists
stat:
ansible.builtin.stat:
path: /etc/pam.d/common-password
register: file_etc_pam_d_common_password
register: common_file_etc_pam_d_common_password
tags:
- nis-install
- nis-install-server
@@ -62,53 +63,60 @@
- ansible_facts['distribution_major_version']|int >= 11
- name: (nis-install-server.yml) Check if default hash for password is 'yescrypt'
shell: "grep -i -q -E '^password.+yescrypt' /etc/pam.d/common-password"
register: presence_of_passwprd_hashing_yescrypt
changed_when:
- presence_of_passwprd_hashing_yescrypt.rc < 1
ansible.builtin.command: grep -i -q -E '^password.+yescrypt' /etc/pam.d/common-password
register: common_presence_of_passwprd_hashing_yescrypt
changed_when: false
failed_when:
- presence_of_passwprd_hashing_yescrypt.rc >= 2
- common_presence_of_passwprd_hashing_yescrypt.rc >= 2
when:
- ansible_facts['distribution'] == "Debian"
- ansible_facts['distribution_major_version']|int >= 11
- file_etc_pam_d_common_password.stat.exists == True
#- ansible_distribution_major_version|int <= 12
- common_file_etc_pam_d_common_password.stat.exists
# - ansible_distribution_major_version|int <= 12
- name: (nis-install-server.yml) Change default password hash for local system
accounts from SHA-512 to yescrypt
shell: perl -i -n -p -e "s/^(password.+)yescrypt/\1sha512/"
/etc/pam.d/common-password
- name: (nis-install-server.yml) Change default password hash for local system accounts from yescrypt to SHA-512
ansible.builtin.replace:
path: /etc/pam.d/common-password
regexp: '^(password.+)yescrypt'
replace: '\1sha512'
when:
- ansible_facts['distribution'] == "Debian"
- ansible_facts['distribution_major_version']|int >= 11
- file_etc_pam_d_common_password.stat.exists == True
- presence_of_passwprd_hashing_yescrypt is changed
#- ansible_facts['distribution_major_version']|int <= 12
- common_file_etc_pam_d_common_password.stat.exists
- common_presence_of_passwprd_hashing_yescrypt.rc == 0
# - ansible_facts['distribution_major_version']|int <= 12
# ---
# /etc/default/nis
# ---
# ---
# /etc/default/nis
# ---
- name: (nis-install-server.yml) Check if file '/etc/default/nis.ORIG' exists
stat:
ansible.builtin.stat:
path: /etc/default/nis.ORIG
register: default_nis_exists
register: common_default_nis_exists
tags:
- nis-install
- nis-install-server
- name: (nis-install-server.yml) Backup existing file /etc/default/nis
command: cp -a /etc/default/nis /etc/default/nis.ORIG
ansible.builtin.copy:
src: /etc/default/nis
dest: /etc/default/nis.ORIG
remote_src: true
force: false
owner: root
group: root
mode: "0644"
when:
- default_nis_exists.stat.exists == False
- not common_default_nis_exists.stat.exists
tags:
- nis-install
- nis-install-server
- name: (nis-install-server.yml) Adjust file /etc/default/nis - set 'NISSERVER'
(server)
replace:
ansible.builtin.replace:
path: /etc/default/nis
regexp: "^NISSERVER=.*"
replace: "NISSERVER=master"
@@ -118,7 +126,7 @@
- name: (nis-install-server.yml) Adjust file /etc/default/nis - set 'NISCLIENT'
(server)
replace:
ansible.builtin.replace:
path: /etc/default/nis
regexp: "^NISCLIENT=.*"
replace: "NISCLIENT=false"
@@ -131,24 +139,31 @@
# ---
- name: (nis-install-server.yml) Check if file '/etc/ypserv.securenets.ORIG' exists
stat:
ansible.builtin.stat:
path: /etc/ypserv.securenets.ORIG
register: ypserv_securenets_orig_exists
register: common_ypserv_securenets_orig_exists
tags:
- nis-install
- nis-install-server
- name: (nis-install-server.yml) Backup existing file /etc/ypserv.securenets
command: cp -a /etc/ypserv.securenets /etc/ypserv.securenets.ORIG
ansible.builtin.copy:
src: /etc/ypserv.securenets
dest: /etc/ypserv.securenets.ORIG
remote_src: true
force: false
owner: root
group: root
mode: "0644"
when:
- ypserv_securenets_orig_exists.stat.exists == False
- not common_ypserv_securenets_orig_exists.stat.exists
tags:
- nis-install
- nis-install-server
- name: (nis-install-server.yml) Comment line like '0.0.0.0 ..' to file
/etc/ypserv.securenets
replace:
ansible.builtin.replace:
path: /etc/ypserv.securenets
regexp: "^(0.0.0.0\\s+.*)"
replace: "#\\1"
@@ -158,7 +173,7 @@
- name: (nis-install-server.yml) Add '255.255.0.0 192.168.0.0' to file
/etc/ypserv.securenets
lineinfile:
ansible.builtin.lineinfile:
path: /etc/ypserv.securenets
line: "255.255.0.0 192.168.0.0"
insertafter: EOF
@@ -172,7 +187,7 @@
- name: (nis-install-server.yml) Add '255.0.0.0 10.0.0.0' to file
/etc/ypserv.securenets
lineinfile:
ansible.builtin.lineinfile:
path: /etc/ypserv.securenets
line: "255.0.0.0 10.0.0.0"
insertafter: EOF
@@ -185,8 +200,13 @@
- nis-install-server
- name: (nis-install-server.yml) Trigger '/usr/lib/yp/ypinit -m'
shell: printf '\n' | /usr/lib/yp/ypinit -m
when: nis_installed.changed
ansible.builtin.command: /usr/lib/yp/ypinit -m
args:
stdin: "\n"
changed_when: false
when:
- ansible_facts['distribution'] == "Debian"
- ansible_facts['distribution_major_version'] | int >= 11
tags:
- nis-install
- nis-install-server
@@ -197,7 +217,7 @@
- name: (nis-install-server.yml) Ensure directoriy 'nis_base_home' (usually
/data/home) exists
file:
ansible.builtin.file:
path: "{{ nis_base_home }}"
owner: root
group: root
@@ -230,9 +250,9 @@
# ---
- name: (nis-install-server.yml) Check if file '/etc/adduser.conf.ORIG exists'
stat:
ansible.builtin.stat:
path: /etc/adduser.conf.ORIG
register: adduser_conf_exists
register: common_adduser_conf_exists
when:
- nis_base_home is defined
- nis_base_home != '/home'
@@ -241,11 +261,18 @@
- nis-install-server
- name: (nis-install-server.yml) Backup existing file /etc/adduser.conf
command: cp -a /etc/adduser.conf /etc/adduser.conf.ORIG
ansible.builtin.copy:
src: /etc/adduser.conf
dest: /etc/adduser.conf.ORIG
remote_src: true
force: false
owner: root
group: root
mode: "0644"
when:
- nis_base_home is defined
- nis_base_home != '/home'
- adduser_conf_exists.stat.exists == False
- not common_adduser_conf_exists.stat.exists
tags:
- nis-install
- nis-install-server
@@ -267,23 +294,30 @@
# ---
- name: (nis-install-server.yml) Check if file '/var/yp/Makefile.ORIG exists'
stat:
ansible.builtin.stat:
path: /var/yp/Makefile.ORIG
register: adduser_conf_exists
register: common_yp_makefile_orig_exists
tags:
- nis-install
- nis-install-server
- name: (nis-install-server.yml) Backup existing file /var/yp/Makefile
command: cp -a /var/yp/Makefile /var/yp/Makefile.ORIG
ansible.builtin.copy:
src: /var/yp/Makefile
dest: /var/yp/Makefile.ORIG
remote_src: true
force: false
owner: root
group: root
mode: "0644"
when:
- adduser_conf_exists.stat.exists == False
- not common_yp_makefile_orig_exists.stat.exists
tags:
- nis-install
- nis-install-server
- name: (nis-install-server.yml) Adjust file '/var/yp/Makefile'
replace:
ansible.builtin.replace:
path: /var/yp/Makefile
regexp: "^#?{{ item }}=.*"
replace: "{{ item }}=true"