Skip to content

Commit dbf4d32

Browse files
committed
split tasks
1 parent 6a42dab commit dbf4d32

4 files changed

Lines changed: 64 additions & 54 deletions

File tree

tasks/configure_banner.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
- name: configure_banner | Apply template {{ motd_banner_template }} on {{ _motd_banner_file_path }}
3+
copy:
4+
content: "{{ motd_banner_template_prepend + _motd_banner_template_content + motd_banner_template_append }}"
5+
dest: "{{ _motd_banner_file_path }}"
6+
owner: root
7+
group: root
8+
mode: '0644'
9+
when: motd_banner_template != None and motd_banner_template|length>0
10+
11+
- name: configure_banner | Ensure line "Banner {{ _motd_banner_file_path }}" is {{ _motd_banner_state }} in {{ _motd_sshd_config_file_path }}
12+
lineinfile:
13+
path: "{{ _motd_sshd_config_file_path }}"
14+
regexp: "^(#?)Banner "
15+
line: Banner {{ _motd_banner_file_path }}
16+
state: "{{ _motd_banner_state }}"
17+
notify: Restart sshd
18+
...

tasks/configure_motd.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
- name: configure_motd | Apply template {{ motd_template }} on {{ _motd_file_path }}
3+
copy:
4+
content: "{{ motd_template_prepend + _motd_template_content + motd_template_append }}"
5+
dest: "{{ _motd_file_path }}"
6+
owner: root
7+
group: root
8+
mode: '0755'
9+
tags:
10+
- molecule-idempotence-notest
11+
12+
- name: configure_motd | Add pam_exec {{ _motd_file_path }} in pam
13+
lineinfile:
14+
path: "{{ item }}"
15+
line: session optional pam_exec.so type=open_session stdout {{ _motd_file_path }}
16+
loop:
17+
- "{{ _motd_pam_login_file_path }}"
18+
- "{{ _motd_pam_sshd_file_path }}"
19+
...

tasks/disable_default_motd.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
- name: disable_default_motd | Get stats of {{ _motd_sshd_config_file_path }}
3+
stat:
4+
path: "{{ _motd_sshd_config_file_path }}"
5+
register: _motd_sshd_config_file_stat
6+
7+
- name: disable_default_motd | Ensure PrintMotd is set to "no" in {{ _motd_sshd_config_file_path }}
8+
lineinfile:
9+
path: "{{ _motd_sshd_config_file_path }}"
10+
regexp: "^PrintMotd "
11+
line: PrintMotd no
12+
when: _motd_sshd_config_file_stat.stat.exists
13+
14+
- name: disable_default_motd | Comment out pam_motd in pam
15+
replace:
16+
path: "{{ item }}"
17+
regexp: '^(session\s+optional\s+pam_motd.so\s+.*)'
18+
replace: '# \1'
19+
loop:
20+
- "{{ _motd_pam_login_file_path }}"
21+
- "{{ _motd_pam_sshd_file_path }}"
22+
...

tasks/main.yml

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,9 @@
11
---
2-
- block:
3-
- name: Get stats of {{ _motd_sshd_config_file_path }}
4-
stat:
5-
path: "{{ _motd_sshd_config_file_path }}"
6-
register: _motd_sshd_config_file_stat
2+
- include_tasks: configure_banner.yml
73

8-
- name: Ensure PrintMotd is set to "no" in {{ _motd_sshd_config_file_path }}
9-
lineinfile:
10-
path: "{{ _motd_sshd_config_file_path }}"
11-
regexp: "^PrintMotd "
12-
line: PrintMotd no
13-
when: _motd_sshd_config_file_stat.stat.exists
14-
15-
- name: Comment out pam_motd in pam
16-
replace:
17-
path: "{{ item }}"
18-
regexp: '^(session\s+optional\s+pam_motd.so\s+.*)'
19-
replace: '# \1'
20-
loop:
21-
- "{{ _motd_pam_login_file_path }}"
22-
- "{{ _motd_pam_sshd_file_path }}"
4+
- name: include_tasks disable_default_motd.yml if motd_disable_default_motd is True
5+
include_tasks: disable_default_motd.yml
236
when: motd_disable_default_motd|bool
247

25-
- name: Apply template {{ motd_banner_template }} on {{ _motd_banner_file_path }}
26-
copy:
27-
content: "{{ motd_banner_template_prepend + _motd_banner_template_content + motd_banner_template_append }}"
28-
dest: "{{ _motd_banner_file_path }}"
29-
owner: root
30-
group: root
31-
mode: '0644'
32-
when: motd_banner_template
33-
34-
- name: Ensure line "Banner {{ _motd_banner_file_path }}" is {{ _motd_banner_state }} in {{ _motd_sshd_config_file_path }}
35-
lineinfile:
36-
path: "{{ _motd_sshd_config_file_path }}"
37-
regexp: "^(#?)Banner "
38-
line: Banner {{ _motd_banner_file_path }}
39-
state: "{{ _motd_banner_state }}"
40-
notify: Restart sshd
41-
42-
- name: Apply template {{ motd_template }} on {{ _motd_file_path }}
43-
copy:
44-
content: "{{ motd_template_prepend + _motd_template_content + motd_template_append }}"
45-
dest: "{{ _motd_file_path }}"
46-
owner: root
47-
group: root
48-
mode: '0755'
49-
tags:
50-
- molecule-idempotence-notest
51-
52-
- name: Add pam_exec {{ _motd_file_path }} in pam
53-
lineinfile:
54-
path: "{{ item }}"
55-
line: session optional pam_exec.so type=open_session stdout {{ _motd_file_path }}
56-
loop:
57-
- "{{ _motd_pam_login_file_path }}"
58-
- "{{ _motd_pam_sshd_file_path }}"
8+
- include_tasks: configure_motd.yml
9+
...

0 commit comments

Comments
 (0)