|
| 1 | +# platform = multi_platform_all |
| 2 | +# reboot = false |
| 3 | +# strategy = configure |
| 4 | +# complexity = low |
| 5 | +# disruption = high |
| 6 | + |
| 7 | +- name: "{{{ rule_title }}} - Initialize variables" |
| 8 | + ansible.builtin.set_fact: |
| 9 | + non_allowed_partitions: ["/", "/lib", "/opt", "/usr", "/bin", "/sbin", "/boot", "/dev", "/proc"] |
| 10 | + home_directories: [] |
| 11 | + allowed_mount_point: [] |
| 12 | + fstab_mount_point_info: [] |
| 13 | + |
| 14 | +- name: "{{{ rule_title }}} - Get home directories from passwd" |
| 15 | + ansible.builtin.getent: |
| 16 | + database: passwd |
| 17 | + |
| 18 | +- name: "{{{ rule_title }}} - Filter home directories based on UID range" |
| 19 | + ansible.builtin.set_fact: |
| 20 | + home_directories: "{{ home_directories + [item.data[4]] }}" |
| 21 | + when: |
| 22 | + - item.data[4] is defined |
| 23 | + - item.data[2]|int >= {{{ uid_min }}} |
| 24 | + - item.data[2]|int != {{{ nobody_uid }}} |
| 25 | + - item.data[4] not in non_allowed_partitions |
| 26 | + with_items: "{{ ansible_facts.getent_passwd | dict2items(key_name='user', value_name='data')}}" |
| 27 | + |
| 28 | +- name: "{{{ rule_title }}} - Gather mount points" |
| 29 | + ansible.builtin.setup: |
| 30 | + filter: ansible_mounts |
| 31 | + |
| 32 | +- name: "{{{ rule_title }}} - Ensure mount options for home directories" |
| 33 | + block: |
| 34 | + |
| 35 | + - name: " {{{ rule_title }}} - Obtain mount point using df and shell" |
| 36 | + ansible.builtin.shell: | |
| 37 | + df {{ item }} | awk '/^\/dev/ {print $6}' |
| 38 | + register: df_output |
| 39 | + with_items: "{{ home_directories }}" |
| 40 | + |
| 41 | + - name: "{{{ rule_title }}} - Set mount point for each home directory" |
| 42 | + ansible.builtin.set_fact: |
| 43 | + allowed_mount_point: "{{ allowed_mount_point + [item.stdout_lines[0]] }}" |
| 44 | + with_items: "{{ df_output.results }}" |
| 45 | + when: |
| 46 | + - item.stdout_lines is defined |
| 47 | + - item.stdout_lines | length > 0 |
| 48 | + - item.stdout_lines[0] != "" |
| 49 | + |
| 50 | + - name: "{{{ rule_title }}} - Obtain full mount information for allowed mount point" |
| 51 | + ansible.builtin.set_fact: |
| 52 | + fstab_mount_point_info: "{{ fstab_mount_point_info + [ ansible_mounts | selectattr('mount', 'equalto', item) | first ]}}" |
| 53 | + with_items: "{{ allowed_mount_point }}" |
| 54 | + when: allowed_mount_point is defined |
| 55 | + |
| 56 | + - name: "{{{ rule_title }}} - Ensure mount option {{{ MOUNTOPTION }}} is in fstab for allowed mount point" |
| 57 | + ansible.builtin.mount: |
| 58 | + path: "{{ item.mount }}" |
| 59 | + src: "{{ item.device }}" |
| 60 | + opts: "{{ item.options }},{{{ MOUNTOPTION }}}" |
| 61 | + state: mounted |
| 62 | + fstype: "{{ item.fstype }}" |
| 63 | + with_items: "{{ fstab_mount_point_info }}" |
| 64 | + when: |
| 65 | + - allowed_mount_point is defined |
| 66 | + - item.mount not in non_allowed_partitions |
| 67 | + - "'{{{ MOUNTOPTION }}}' not in item.options" |
0 commit comments