|
10 | 10 | # updated the Ansible pamd module to do that, we will need to use regexp |
11 | 11 | # for now. |
12 | 12 |
|
13 | | - |
14 | | -# declare the XCCDF vars if any |
15 | | -{{% for arg in ARGUMENTS %}} |
16 | | -{{% if arg['variable']|length %}} |
17 | | -- (xccdf-var var_password_pam_{{{ arg['variable'] }}}) |
| 13 | +{{% if product == 'sle16' %}} |
| 14 | +- name: Copy default /usr/lib/pam.d/{{ '{{{ PATH }}}' | basename }} to {{{ PATH }}} |
| 15 | + ansible.builtin.copy: |
| 16 | + src: /usr/lib/pam.d/{{ '{{{ PATH }}}' | basename }} |
| 17 | + dest: {{{ PATH }}} |
| 18 | + force: no |
| 19 | + mode: '0644' |
18 | 20 | {{% endif %}} |
19 | | -{{% endfor %}} |
20 | 21 |
|
21 | 22 | - name: Set control_flag fact |
22 | 23 | ansible.builtin.set_fact: |
|
33 | 34 | path: {{{ PATH }}} |
34 | 35 | line: '{{{ TYPE }}} {{{ CONTROL_FLAG }}} {{{ MODULE }}}' |
35 | 36 | state: present |
36 | | - when: check_pam_module_result.stdout is defined and '"{{{ MODULE }}}" not in check_pam_module_result.stdout' |
| 37 | + when: check_pam_module_result is not skipped and check_pam_module_result.stdout is defined and "{{{ MODULE }}}" not in check_pam_module_result.stdout |
37 | 38 |
|
38 | 39 | - name: Ensure '{{{ MODULE }}}' module has conforming control flag |
39 | 40 | ansible.builtin.lineinfile: |
40 | 41 | path: {{{ PATH }}} |
41 | 42 | regexp: '^(\s*{{{ TYPE }}}\s+)\S+(\s+{{{ MODULE }}}\s+.*)' |
42 | 43 | line: '\g<1>{{{ CONTROL_FLAG }}}\g<2>' |
43 | 44 | backrefs: yes |
44 | | - when: control_flag|length |
| 45 | + when: check_pam_module_result is not skipped and control_flag|length |
45 | 46 |
|
46 | 47 | {{% for arg in ARGUMENTS %}} |
47 | 48 | # NOTE: if 'remove_argument' is present and set to some value, we assume |
|
56 | 57 | {{% elif arg['variable']|length %}} |
57 | 58 | # NOTE(gyee): if 'var' is used, user is meant to set the argument to a |
58 | 59 | # static value |
| 60 | +{{% if arg['variable_name'] %}} |
| 61 | +{{% set pam_variable_name = arg['variable_name'] %}} |
| 62 | +{{% else %}} |
| 63 | +{{% set pam_variable_name = "var_password_pam_" + arg['variable'] %}} |
| 64 | +{{% endif %}} |
| 65 | +{{{ ansible_instantiate_variables(pam_variable_name) }}} |
| 66 | + |
| 67 | +{{% set pam_variable_value = "{{ " + pam_variable_name + " }}" %}} |
59 | 68 |
|
60 | | -- name: Ensure "{{{ MODULE }}}" module has argument "{{{ arg['variable'] }}}={{ var_password_pam_{{{ arg['variable'] }}} }}" |
| 69 | +- name: Ensure "{{{ MODULE }}}" module has argument "{{{ arg['variable'] }}}={{{ pam_variable_value }}}" |
61 | 70 | ansible.builtin.lineinfile: |
62 | 71 | path: {{{ PATH }}} |
63 | 72 | regexp: '^(\s*{{{ TYPE }}}\s+{{{ CONTROL_FLAG }}}\s+{{{ MODULE }}}(?:\s+\S+)*\s+{{{ arg['variable'] }}}=)(?:\S+)((\s+\S+)*\s*\\*\s*)$' |
64 | | - line: '\g<1>{{ var_password_pam_{{{ arg['variable'] }}} }}\g<2>' |
| 73 | + line: '\g<1>{{{ pam_variable_value }}}\g<2>' |
65 | 74 | backrefs: yes |
| 75 | + when: check_pam_module_result is not skipped |
66 | 76 |
|
67 | 77 | - name: Check the presence of "{{{ arg['variable'] }}}" argument in "{{{ MODULE }}}" module |
68 | 78 | ansible.builtin.shell: | |
|
74 | 84 | ansible.builtin.lineinfile: |
75 | 85 | path: {{{ PATH }}} |
76 | 86 | regexp: '^(\s*{{{ TYPE }}}\s+{{{ CONTROL_FLAG }}}\s+{{{ MODULE }}})((\s+\S+)*\s*(\\)*$)' |
77 | | - line: '\g<1> {{{ arg['variable'] }}}={{ var_password_pam_{{{ arg['variable'] }}} }}\g<2>' |
| 87 | + line: '\g<1> {{{ arg['variable'] }}}={{{ pam_variable_value }}}\g<2>' |
78 | 88 | backrefs: yes |
79 | | - when: check_pam_module_argument_result is not skipped and '"{{{ arg['variable'] }}}" not in check_pam_module_argument_result.stdout' |
| 89 | + when: check_pam_module_argument_result is not skipped and "{{{ arg['variable'] }}}" not in check_pam_module_argument_result.stdout |
80 | 90 | {{% else %}} |
81 | 91 | - name: Set argument_value fact |
82 | 92 | ansible.builtin.set_fact: |
|
102 | 112 | regexp: '^(\s*{{{ TYPE }}}\s+{{{ CONTROL_FLAG }}}\s+{{{ MODULE }}})((\s+\S+)*\s*(\\)*$)' |
103 | 113 | line: '\g<1> {{{ arg['new_argument'] }}}\g<2>' |
104 | 114 | backrefs: yes |
105 | | - when: check_pam_module_argument_result is not skipped and '"{{{ arg['argument'] }}}" not in check_pam_module_argument_result.stdout' |
| 115 | + when: check_pam_module_argument_result is not skipped and "{{{ arg['argument'] }}}" not in check_pam_module_argument_result.stdout |
106 | 116 | {{% endif %}} |
107 | 117 | {{% endfor %}} |
0 commit comments