Skip to content

Commit

Permalink
Improve ansible remediation of accounts_umask_etc_login_defs.
Browse files Browse the repository at this point in the history
  • Loading branch information
ggbecker committed Sep 8, 2022
1 parent 8abc993 commit e13fa3b
Showing 1 changed file with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,35 @@
# disruption = low
{{{ ansible_instantiate_variables("var_accounts_user_umask") }}}

- name: Ensure the Default UMASK is Set Correctly
replace:
- name: Check if UMASK is already set
ansible.builtin.lineinfile:
path: /etc/login.defs
regexp: "^UMASK"
replace: "UMASK {{ var_accounts_user_umask }}"
register: umask_replace
regexp: ^(?!#)(\s*)UMASK\s+.*
state: absent
check_mode: yes
changed_when: false
register: result_umask_is_set

- name: Check if UMASK is already correctly set
ansible.builtin.lineinfile:
path: /etc/login.defs
regexp: '^(?!#)(\s*)UMASK\s+{{ var_accounts_user_umask }}\s*$'
state: absent
check_mode: yes
changed_when: false
when: result_umask_is_set.found == 1
register: result_umask_is_correctly_set

- name: Replace user UMASK in /etc/login.defs
ansible.builtin.replace:
path: /etc/login.defs
regexp: ^(?!#)(\s*)UMASK(\s+).*
replace: '\g<1>UMASK\g<2>{{ var_accounts_user_umask }}'
when: result_umask_is_correctly_set is defined and result_umask_is_correctly_set.found == 0

- name: Ensure the Default UMASK is Appended Correctly
lineinfile:
create: yes
path: /etc/login.defs
line: "UMASK {{ var_accounts_user_umask }}"
when: umask_replace is not changed
when: result_umask_is_set.found == 0

0 comments on commit e13fa3b

Please sign in to comment.