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
+58 -38
View File
@@ -6,11 +6,11 @@
- name: (nis-install-client.yml) Set (nis) default domain (/etc/defaultdomain)
ansible.builtin.template:
dest: /etc/defaultdomain
dest: /etc/defaultdomain
src: etc/defaultdomain.j2
owner: root
group: root
mode: 0644
mode: "0644"
tags:
- nis-install
- nis-install-client
@@ -21,13 +21,13 @@
src: etc/yp.conf.j2
owner: root
group: root
mode: 0644
mode: "0644"
tags:
- nis-install
- nis-install-client
- name: (nis-install-client.yml) Install nis common packages
package:
ansible.builtin.package:
name: "{{ item }}"
state: present
with_items: "{{ nis_common_packages }}"
@@ -41,23 +41,30 @@
# ---
- name: (nis-install-client.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-client
- name: (nis-install-client.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-client
- name: (nis-install-client.yml) Adjust file /etc/default/nis - set 'NISSERVER' (client)
replace:
ansible.builtin.replace:
path: /etc/default/nis
regexp: '^NISSERVER=.*'
replace: 'NISSERVER=false'
@@ -66,7 +73,7 @@
- nis-install-client
- name: (nis-install-client.yml) Adjust file /etc/default/nis - set 'NISCLIENT' (client)
replace:
ansible.builtin.replace:
path: /etc/default/nis
regexp: '^NISCLIENT=.*'
replace: 'NISCLIENT=true'
@@ -75,7 +82,7 @@
- nis-install-client
- name: (nis-install-client.yml) Adjust file /etc/default/nis - set 'YPBINDARGS' (client)
replace:
ansible.builtin.replace:
path: /etc/default/nis
regexp: '^YPBINDARGS=.*'
replace: 'YPBINDARGS='
@@ -89,7 +96,7 @@
# ---
- name: (nis-install-client.yml) Add '+::::::' to file /etc/passwd
lineinfile:
ansible.builtin.lineinfile:
path: /etc/passwd
line: '+::::::'
insertafter: EOF
@@ -103,7 +110,7 @@
- nis-install-client
- name: (nis-install-client.yml) Add '+:::' to file /etc/group
lineinfile:
ansible.builtin.lineinfile:
path: /etc/group
line: '+:::'
insertafter: EOF
@@ -117,7 +124,7 @@
- nis-install-client
- name: (nis-install-client.yml) Add '+::::::::' to file /etc/shadow
lineinfile:
ansible.builtin.lineinfile:
path: /etc/shadow
line: '+::::::::'
insertafter: EOF
@@ -136,23 +143,30 @@
# ---
- name: (nis-install-client.yml) Check if file '/etc/hosts.ORIG' exists
stat:
ansible.builtin.stat:
path: /etc/hosts.ORIG
register: etc_hosts_orig_exists
register: common_etc_hosts_orig_exists
tags:
- nis-install
- nis-install-client
- name: (nis-install-client.yml) Backup existing file /etc/hosts
command: cp -a /etc/hosts /etc/hosts.ORIG
ansible.builtin.copy:
src: /etc/hosts
dest: /etc/hosts.ORIG
remote_src: true
force: false
owner: root
group: root
mode: "0644"
when:
- etc_hosts_orig_exists.stat.exists == False
- not common_etc_hosts_orig_exists.stat.exists
tags:
- nis-install
- nis-install-client
- name: (nis-install-client.yml) Add nis-server to file /etc/hosts
lineinfile:
ansible.builtin.lineinfile:
path: /etc/hosts
line: '{{ nis_server_address }} {{ nis_server_name }} {{ nis_server_name.split(".")[0] }}'
insertafter: EOF
@@ -170,23 +184,30 @@
# ---
- name: (nis-install-client.yml) Check if file '/etc/nsswitch.conf.ORIG' exists
stat:
ansible.builtin.stat:
path: /etc/nsswitch.conf.ORIG
register: nsswitch_conf_orig_exists
register: common_nsswitch_conf_orig_exists
tags:
- nis-install
- nis-install
- nis-install-client
- name: (nis-install-client.yml) Backup existing file /etc/nsswitch.conf
command: cp -a /etc/nsswitch.conf /etc/nsswitch.conf.ORIG
ansible.builtin.copy:
src: /etc/nsswitch.conf
dest: /etc/nsswitch.conf.ORIG
remote_src: true
force: false
owner: root
group: root
mode: "0644"
when:
- nsswitch_conf_orig_exists.stat.exists == False
- not common_nsswitch_conf_orig_exists.stat.exists
tags:
- nis-install
- nis-install-client
- name: (nis-install-client.yml) Adjust file /etc/nsswitch.conf (set hosts)
replace:
ansible.builtin.replace:
path: /etc/nsswitch.conf
regexp: '(hosts:\s+files)\s+((?!nis).*)$'
replace: '\1 nis \2'
@@ -195,14 +216,14 @@
- nis-install-client
- name: (nis-install-client.yml) Adjust file /etc/nsswitch.conf (set passwd/group/shadow)
replace:
ansible.builtin.replace:
path: /etc/nsswitch.conf
regexp: '^({{ item }}:\s+((?!nis).)*)$'
replace: '\1 nis'
with_items:
- passwd
- group
- shadow
- passwd
- group
- shadow
tags:
- nis-install
- nis-install-client
@@ -239,7 +260,7 @@
# - systemctl restart systemd-logind.service
- name: (nis-install-client.yml) Ensure directory /etc/systemd/system/systemd-logind.service.d exists
file:
ansible.builtin.file:
path: /etc/systemd/system/systemd-logind.service.d
owner: root
group: root
@@ -251,7 +272,7 @@
- nis-install-client
- name: (nis-install-client.yml) Ensure file /files/etc/systemd/system/systemd-logind.service.d/nis_allow_network.conf exists
copy:
ansible.builtin.copy:
src: "{{ role_path + '/files/etc/systemd/system/systemd-logind.service.d/nis_allow_network.conf' }}"
dest: /etc/systemd/system/systemd-logind.service.d/nis_allow_network.conf
owner: root
@@ -281,7 +302,7 @@
# - cat /etc/systemd/system/rpcbind.socket.d/override.conf
- name: (nis-install-client.yml) Ensure directory /etc/systemd/system/rpcbind.socket.d exists
file:
ansible.builtin.file:
path: /etc/systemd/system/rpcbind.socket.d
owner: root
group: root
@@ -293,7 +314,7 @@
- nis-install-client
- name: (nis-install-client.yml) Ensure file /files/etc/systemd/system/rpcbind.socket.d/override.conf exists
copy:
ansible.builtin.copy:
src: "{{ role_path + '/files/etc/systemd/system/rpcbind.socket.d/override.conf' }}"
dest: /etc/systemd/system/rpcbind.socket.d/override.conf
owner: root
@@ -307,12 +328,11 @@
- nis-install-client
- name: Make sure service rpcbind, nscd and ypbind are started and enabled
systemd:
ansible.builtin.systemd:
name: "{{ item }}"
state: restarted
enabled: true
with_items:
- rpcbind
- nscd
- ypbind
- rpcbind
- nscd
- ypbind