Refactor Ansible tasks and templates for improved consistency and clarity
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
# ---
|
||||
|
||||
- name: (samba-install.yml) Ensure samba packages server (buster) are installed.
|
||||
package:
|
||||
ansible.builtin.package:
|
||||
pkg: "{{ apt_install_server_samba }}"
|
||||
state: present
|
||||
when:
|
||||
@@ -13,7 +13,7 @@
|
||||
- samba-server
|
||||
|
||||
- name: (samba-install.yml) Ensure quarantine directory exists
|
||||
file:
|
||||
ansible.builtin.file:
|
||||
path: /data/samba/QUARANTINE
|
||||
owner: root
|
||||
group: root
|
||||
@@ -28,13 +28,13 @@
|
||||
- samba-virusfilter
|
||||
|
||||
- name: (samba-install.yml) Ensure samba share directories exists
|
||||
file:
|
||||
ansible.builtin.file:
|
||||
path: "{{ item.path }}"
|
||||
owner: "root"
|
||||
group: "{{ item.group_write_list }}"
|
||||
mode: "{{ item.dir_create_mask | default('2770', true) }}"
|
||||
state: directory
|
||||
recurse: no
|
||||
recurse: false
|
||||
with_items: "{{ samba_shares }}"
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
@@ -48,7 +48,7 @@
|
||||
# ---
|
||||
|
||||
- name: (samba-install.yml) Ensure virusfilter (ClamAV) packages are installed
|
||||
package:
|
||||
ansible.builtin.package:
|
||||
pkg: "{{ apt_install_server_samba_virusfilter }}"
|
||||
state: present
|
||||
when:
|
||||
@@ -60,12 +60,12 @@
|
||||
- samba-virusfilter
|
||||
|
||||
- name: (samba-config-server.yml) Check if ClamAV virus databases are present
|
||||
find:
|
||||
ansible.builtin.find:
|
||||
paths: /var/lib/clamav
|
||||
patterns:
|
||||
- "*.cvd"
|
||||
- "*.cld"
|
||||
register: clamav_db_files
|
||||
register: common_clamav_db_files
|
||||
when:
|
||||
- inventory_hostname in groups['samba_server']
|
||||
- samba_shares | selectattr('vfs_object_virusfilter', 'defined') | selectattr('vfs_object_virusfilter', 'equalto', true) | list | length > 0
|
||||
@@ -74,23 +74,23 @@
|
||||
- samba-virusfilter
|
||||
|
||||
- name: (samba-config-server.yml) Stop clamav-freshclam service before initial database download
|
||||
service:
|
||||
ansible.builtin.service:
|
||||
name: clamav-freshclam
|
||||
state: stopped
|
||||
failed_when: false
|
||||
when:
|
||||
- inventory_hostname in groups['samba_server']
|
||||
- samba_shares | selectattr('vfs_object_virusfilter', 'defined') | selectattr('vfs_object_virusfilter', 'equalto', true) | list | length > 0
|
||||
- clamav_db_files.files | length == 0
|
||||
- common_clamav_db_files.files | length == 0
|
||||
tags:
|
||||
- samba-server
|
||||
- samba-virusfilter
|
||||
|
||||
- name: (samba-config-server.yml) Ensure clamav-daemon service is started before database update
|
||||
service:
|
||||
ansible.builtin.service:
|
||||
name: clamav-daemon
|
||||
state: started
|
||||
enabled: yes
|
||||
enabled: true
|
||||
failed_when: false
|
||||
when:
|
||||
- inventory_hostname in groups['samba_server']
|
||||
@@ -100,20 +100,21 @@
|
||||
- samba-virusfilter
|
||||
|
||||
- name: (samba-config-server.yml) Download initial ClamAV virus databases via freshclam
|
||||
command: freshclam
|
||||
ansible.builtin.command: freshclam
|
||||
changed_when: true
|
||||
when:
|
||||
- inventory_hostname in groups['samba_server']
|
||||
- samba_shares | selectattr('vfs_object_virusfilter', 'defined') | selectattr('vfs_object_virusfilter', 'equalto', true) | list | length > 0
|
||||
- clamav_db_files.files | length == 0
|
||||
- common_clamav_db_files.files | length == 0
|
||||
tags:
|
||||
- samba-server
|
||||
- samba-virusfilter
|
||||
|
||||
- name: (samba-config-server.yml) Ensure clamav-daemon service is enabled and started
|
||||
service:
|
||||
ansible.builtin.service:
|
||||
name: clamav-daemon
|
||||
state: started
|
||||
enabled: yes
|
||||
enabled: true
|
||||
when:
|
||||
- inventory_hostname in groups['samba_server']
|
||||
- samba_shares | selectattr('vfs_object_virusfilter', 'defined') | selectattr('vfs_object_virusfilter', 'equalto', true) | list | length > 0
|
||||
@@ -122,10 +123,10 @@
|
||||
- samba-virusfilter
|
||||
|
||||
- name: (samba-config-server.yml) Ensure clamav-freshclam service is enabled and started
|
||||
service:
|
||||
ansible.builtin.service:
|
||||
name: clamav-freshclam
|
||||
state: started
|
||||
enabled: yes
|
||||
enabled: true
|
||||
when:
|
||||
- inventory_hostname in groups['samba_server']
|
||||
- samba_shares | selectattr('vfs_object_virusfilter', 'defined') | selectattr('vfs_object_virusfilter', 'equalto', true) | list | length > 0
|
||||
@@ -134,10 +135,10 @@
|
||||
- samba-virusfilter
|
||||
|
||||
- name: (samba-install.yml) Ensure clamav user is member of all NIS groups
|
||||
user:
|
||||
ansible.builtin.user:
|
||||
name: clamav
|
||||
groups: "{{ item.name }}"
|
||||
append: yes
|
||||
append: true
|
||||
loop: "{{ nis_groups }}"
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
@@ -151,10 +152,10 @@
|
||||
- samba-virusfilter
|
||||
|
||||
- name: (samba-config-server.yml) Ensure clamav user is member of all NIS user groups (homes virusfilter)
|
||||
user:
|
||||
ansible.builtin.user:
|
||||
name: clamav
|
||||
groups: "{{ item.name }}"
|
||||
append: yes
|
||||
append: true
|
||||
loop: "{{ nis_user }}"
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
@@ -173,7 +174,7 @@
|
||||
loop: "{{ nis_user }}"
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
register: samba_user_getent
|
||||
register: common_samba_user_getent
|
||||
when:
|
||||
- inventory_hostname in groups['samba_server']
|
||||
- samba_homes_virusfilter | default(false) | bool
|
||||
@@ -183,11 +184,11 @@
|
||||
- samba-virusfilter
|
||||
|
||||
- name: (samba-config-server.yml) Ensure home directories are group-traversable for clamd (homes virusfilter)
|
||||
file:
|
||||
ansible.builtin.file:
|
||||
path: "{{ item.ansible_facts.getent_passwd[item.item.name][4] }}"
|
||||
mode: "0750"
|
||||
state: directory
|
||||
loop: "{{ samba_user_getent.results | default([]) }}"
|
||||
loop: "{{ common_samba_user_getent.results | default([]) }}"
|
||||
loop_control:
|
||||
label: "{{ item.item.name }}"
|
||||
when:
|
||||
@@ -217,7 +218,7 @@
|
||||
- samba-virusfilter
|
||||
|
||||
- name: (samba-config-server.yml) Ensure AllowAllMatchScan is enabled in clamd.conf
|
||||
lineinfile:
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/clamav/clamd.conf
|
||||
regexp: "^#?\\s*AllowAllMatchScan\\s"
|
||||
line: "AllowAllMatchScan true"
|
||||
@@ -236,19 +237,26 @@
|
||||
# ---
|
||||
|
||||
- name: (samba-install.yml) Check if file '/etc/samba/smb.conf.ORIG exists'
|
||||
stat:
|
||||
ansible.builtin.stat:
|
||||
path: /etc/samba/smb.conf.ORIG
|
||||
register: smb_conf_exists
|
||||
register: common_smb_conf_exists
|
||||
when:
|
||||
- inventory_hostname in groups['samba_server']
|
||||
tags:
|
||||
- samba-server
|
||||
|
||||
- name: (samba-install.yml) Backup existing file /etc/samba/smb.conf
|
||||
command: cp -a /etc/samba/smb.conf /etc/samba/smb.conf.ORIG
|
||||
ansible.builtin.copy:
|
||||
src: /etc/samba/smb.conf
|
||||
dest: /etc/samba/smb.conf.ORIG
|
||||
remote_src: true
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
force: false
|
||||
when:
|
||||
- inventory_hostname in groups['samba_server']
|
||||
- smb_conf_exists.stat.exists == False
|
||||
- not common_smb_conf_exists.stat.exists
|
||||
tags:
|
||||
- samba-server
|
||||
|
||||
@@ -258,7 +266,7 @@
|
||||
src: etc/samba/smb.conf.j2
|
||||
owner: root
|
||||
group: root
|
||||
mode: 644
|
||||
mode: "0644"
|
||||
when:
|
||||
- inventory_hostname in groups['samba_server']
|
||||
notify:
|
||||
@@ -268,12 +276,12 @@
|
||||
- samba-server
|
||||
|
||||
- name: (samba-install.yml) Ensure file /etc/samba/users.map exists
|
||||
copy:
|
||||
ansible.builtin.copy:
|
||||
src: "{{ role_path + '/files/etc/samba/users.map' }}"
|
||||
dest: /etc/samba/users.map
|
||||
owner: root
|
||||
group: root
|
||||
mode: 644
|
||||
mode: "0644"
|
||||
when:
|
||||
- inventory_hostname in groups['samba_server']
|
||||
notify:
|
||||
@@ -287,9 +295,9 @@
|
||||
# ---
|
||||
|
||||
- name: (samba-install.yml) Check if file '/root/bin/samba/clean_samba_trash.sh' exists
|
||||
stat:
|
||||
ansible.builtin.stat:
|
||||
path: /root/bin/samba/clean_samba_trash.sh
|
||||
register: clean_samba_trash_exists
|
||||
register: common_clean_samba_trash_exists
|
||||
when:
|
||||
- inventory_hostname in groups['samba_server']
|
||||
tags:
|
||||
@@ -300,9 +308,12 @@
|
||||
ansible.builtin.template:
|
||||
dest: /root/bin/samba/conf/clean_samba_trash.conf
|
||||
src: root/bin/samba/conf/clean_samba_trash.conf.j2
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
when:
|
||||
- inventory_hostname in groups['samba_server']
|
||||
- clean_samba_trash_exists.stat.exists|bool
|
||||
- common_clean_samba_trash_exists.stat.exists | bool
|
||||
tags:
|
||||
- samba-server
|
||||
- samba-cron
|
||||
@@ -314,7 +325,7 @@
|
||||
state: absent
|
||||
check_mode: true
|
||||
changed_when: false
|
||||
register: clean_samba_trash_dirs
|
||||
register: common_clean_samba_trash_dirs
|
||||
when:
|
||||
- inventory_hostname in groups['samba_server']
|
||||
tags: [samba-server, samba-cron]
|
||||
@@ -331,8 +342,8 @@
|
||||
job: "{{ samba_cronjob_trash_dirs.job }}"
|
||||
when:
|
||||
- inventory_hostname in groups['samba_server']
|
||||
- clean_samba_trash_exists.stat.exists | bool
|
||||
- (clean_samba_trash_dirs.found | int) > 0
|
||||
- common_clean_samba_trash_exists.stat.exists | bool
|
||||
- (common_clean_samba_trash_dirs.found | int) > 0
|
||||
tags: [samba-server, samba-cron]
|
||||
|
||||
# ---
|
||||
@@ -342,7 +353,7 @@
|
||||
- name: (samba-config-server.yml) Check if file '/root/bin/samba/set_permissions_samba_shares.sh' exists
|
||||
ansible.builtin.stat:
|
||||
path: /root/bin/samba/set_permissions_samba_shares.sh
|
||||
register: set_permissions_on_samba_shares_exists
|
||||
register: common_set_permissions_on_samba_shares_exists
|
||||
when:
|
||||
- inventory_hostname in groups['samba_server']
|
||||
tags: [samba-server, samba-cron]
|
||||
@@ -351,9 +362,12 @@
|
||||
ansible.builtin.template:
|
||||
dest: /root/bin/samba/conf/set_permissions_samba_shares.conf
|
||||
src: root/bin/samba/conf/set_permissions_samba_shares.conf.j2
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
when:
|
||||
- inventory_hostname in groups['samba_server']
|
||||
- set_permissions_on_samba_shares_exists.stat.exists | bool
|
||||
- common_set_permissions_on_samba_shares_exists.stat.exists | bool
|
||||
tags: [samba-server, samba-cron]
|
||||
|
||||
- name: (samba-config-server.yml) Creates a cron job for setting permissions to samba dirs
|
||||
@@ -368,7 +382,7 @@
|
||||
job: "{{ samba_cronjob_permissions.job }}"
|
||||
when:
|
||||
- inventory_hostname in groups['samba_server']
|
||||
- (clean_samba_trash_dirs.found | int) > 0 # << int -> bool
|
||||
- (common_clean_samba_trash_dirs.found | int) > 0 # << int -> bool
|
||||
tags: [samba-server, samba-cron]
|
||||
|
||||
# ---
|
||||
@@ -376,7 +390,7 @@
|
||||
# ---
|
||||
|
||||
- name: (samba-install.yml) Ensure samba packages clients are installed.
|
||||
package:
|
||||
ansible.builtin.package:
|
||||
pkg: "{{ apt_install_client_samba }}"
|
||||
state: present
|
||||
when:
|
||||
|
||||
Reference in New Issue
Block a user