|
5 | 5 | # disruption = low |
6 | 6 |
|
7 | 7 | {{{ ansible_instantiate_variables("var_sudo_timestamp_timeout") }}} |
8 | | -- name: "Find out if /etc/sudoers.d/* files contain 'Defaults timestamp_timeout' to be deduplicated" |
9 | | - find: |
| 8 | + |
| 9 | +- name: "{{{ rule_title }}} - Find /etc/sudoers.d/* files containing 'Defaults timestamp_timeout'" |
| 10 | + ansible.builtin.find: |
10 | 11 | path: "/etc/sudoers.d" |
11 | 12 | patterns: "*" |
12 | 13 | contains: '^[\s]*Defaults\s.*\btimestamp_timeout[\s]*=.*' |
13 | 14 | register: sudoers_d_defaults_timestamp_timeout |
14 | 15 |
|
15 | | -- name: "Remove found occurrences of 'Defaults timestamp_timeout' from /etc/sudoers.d/* files" |
16 | | - lineinfile: |
| 16 | +- name: "{{{ rule_title }}} - Remove 'Defaults timestamp_timeout' from /etc/sudoers.d/* files" |
| 17 | + ansible.builtin.lineinfile: |
17 | 18 | path: "{{ item.path }}" |
18 | 19 | regexp: '^[\s]*Defaults\s.*\btimestamp_timeout[\s]*=.*' |
19 | 20 | state: absent |
20 | 21 | with_items: "{{ sudoers_d_defaults_timestamp_timeout.files }}" |
21 | 22 |
|
22 | | -- name: Ensure timestamp_timeout is enabled with the appropriate value in /etc/sudoers |
23 | | - lineinfile: |
| 23 | +- name: "{{{ rule_title }}} - Ensure timestamp_timeout has the appropriate value in /etc/sudoers" |
| 24 | + ansible.builtin.lineinfile: |
24 | 25 | path: /etc/sudoers |
25 | 26 | regexp: '^[\s]*Defaults\s(.*)\btimestamp_timeout[\s]*=[\s]*[-]?\w+\b(.*)$' |
26 | 27 | line: 'Defaults \1timestamp_timeout={{ var_sudo_timestamp_timeout }}\2' |
27 | 28 | validate: /usr/sbin/visudo -cf %s |
28 | 29 | backrefs: yes |
29 | 30 | register: edit_sudoers_timestamp_timeout_option |
30 | 31 |
|
31 | | -- name: Enable timestamp_timeout option with appropriate value in /etc/sudoers |
32 | | - lineinfile: # noqa 503 |
| 32 | +- name: "{{{ rule_title }}} - Enable timestamp_timeout option with correct value in /etc/sudoers" |
| 33 | + ansible.builtin.lineinfile: # noqa 503 |
33 | 34 | path: /etc/sudoers |
34 | 35 | line: 'Defaults timestamp_timeout={{ var_sudo_timestamp_timeout }}' |
35 | 36 | validate: /usr/sbin/visudo -cf %s |
36 | | - when: edit_sudoers_timestamp_timeout_option is defined and not edit_sudoers_timestamp_timeout_option.changed |
| 37 | + when: > |
| 38 | + edit_sudoers_timestamp_timeout_option is defined and |
| 39 | + not edit_sudoers_timestamp_timeout_option.changed |
| 40 | +
|
| 41 | +- name: "{{{ rule_title }}} - Remove timestamp_timeout wrong values in /etc/sudoers" |
| 42 | + ansible.builtin.lineinfile: |
| 43 | + path: /etc/sudoers |
| 44 | + regexp: '^[\s]*Defaults\s.*\btimestamp_timeout[\s]*=[\s]*(?!{{ |
| 45 | + var_sudo_timestamp_timeout }}\b)[-]?\w+\b.*$' |
| 46 | + state: absent |
| 47 | + validate: /usr/sbin/visudo -cf %s |
0 commit comments