Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
92cb5bf55e | |||
9770e5d43c | |||
cf7e3da48e | |||
dbf4d327cf | |||
6a42daba46 |
4
.github/workflows/molecule.yml
vendored
4
.github/workflows/molecule.yml
vendored
@ -30,8 +30,8 @@ jobs:
|
|||||||
config:
|
config:
|
||||||
- image: "amazonlinux"
|
- image: "amazonlinux"
|
||||||
tag: "latest"
|
tag: "latest"
|
||||||
- image: "centos"
|
- image: "fedora"
|
||||||
tag: "8"
|
tag: "28"
|
||||||
- image: "debian"
|
- image: "debian"
|
||||||
tag: "11"
|
tag: "11"
|
||||||
- image: "debian"
|
- image: "debian"
|
||||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
|||||||
|
###VSCode###
|
||||||
|
.vscode
|
||||||
###MacOS###
|
###MacOS###
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ System info:
|
|||||||
Hostname·········: claranet_motd_ubuntu-20.04
|
Hostname·········: claranet_motd_ubuntu-20.04
|
||||||
Distro···········: Ubuntu 20.04.3 LTS
|
Distro···········: Ubuntu 20.04.3 LTS
|
||||||
Kernel···········: Linux 5.10.47-linuxkit
|
Kernel···········: Linux 5.10.47-linuxkit
|
||||||
Updates available: 6 (2 security)
|
|
||||||
Uptime···········: up 2 days, 23 hours, 18 minutes
|
Uptime···········: up 2 days, 23 hours, 18 minutes
|
||||||
Load·············: 1.33 (1m), 0.43 (5m), 0.20 (15m)
|
Load·············: 1.33 (1m), 0.43 (5m), 0.20 (15m)
|
||||||
Processes········: 13 (root), 3 (user), 16 (total)
|
Processes········: 13 (root), 3 (user), 16 (total)
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
---
|
---
|
||||||
motd_disable_default_motd: true
|
motd_disable_default_motd: true
|
||||||
motd_banner_template: https://raw.githubusercontent.com/claranet/motd/master/banner
|
|
||||||
motd_template: https://raw.githubusercontent.com/claranet/motd/master/scripts/00-basic
|
motd_template: https://raw.githubusercontent.com/claranet/motd/master/scripts/00-basic
|
||||||
motd_banner_template_prepend: ""
|
|
||||||
motd_banner_template_append: ""
|
|
||||||
motd_template_prepend: ""
|
motd_template_prepend: ""
|
||||||
motd_template_append: |
|
motd_template_append: |
|
||||||
|
|
||||||
@ -13,5 +10,3 @@ motd_template_append: |
|
|||||||
|
|
||||||
motd_template_username: ""
|
motd_template_username: ""
|
||||||
motd_template_password: ""
|
motd_template_password: ""
|
||||||
motd_banner_template_username: "{{ motd_template_username }}"
|
|
||||||
motd_banner_template_password: "{{ motd_template_password }}"
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
hosts: all
|
hosts: all
|
||||||
roles:
|
roles:
|
||||||
- role: claranet.motd
|
- role: claranet.motd
|
||||||
motd_banner_template: null
|
|
||||||
|
|
||||||
pre_tasks:
|
pre_tasks:
|
||||||
- name: "Update APT cache"
|
- name: "Update APT cache"
|
||||||
|
@ -12,11 +12,6 @@ motd_file_path = "/usr/local/bin/dynmotd"
|
|||||||
pam_line = f"session optional pam_exec.so type=open_session stdout {motd_file_path}"
|
pam_line = f"session optional pam_exec.so type=open_session stdout {motd_file_path}"
|
||||||
|
|
||||||
|
|
||||||
def test_banner_file(host):
|
|
||||||
file = host.file("/etc/banner")
|
|
||||||
assert not file.exists
|
|
||||||
|
|
||||||
|
|
||||||
def test_motd_file(host):
|
def test_motd_file(host):
|
||||||
file = host.file(motd_file_path)
|
file = host.file(motd_file_path)
|
||||||
assert file.exists
|
assert file.exists
|
||||||
|
19
tasks/configure_motd.yml
Normal file
19
tasks/configure_motd.yml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
---
|
||||||
|
- name: configure_motd | Apply template {{ motd_template }} on {{ _motd_file_path }}
|
||||||
|
copy:
|
||||||
|
content: "{{ motd_template_prepend + _motd_template_content + motd_template_append }}"
|
||||||
|
dest: "{{ _motd_file_path }}"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: '0755'
|
||||||
|
tags:
|
||||||
|
- molecule-idempotence-notest
|
||||||
|
|
||||||
|
- name: configure_motd | Add pam_exec {{ _motd_file_path }} in pam
|
||||||
|
lineinfile:
|
||||||
|
path: "{{ item }}"
|
||||||
|
line: session optional pam_exec.so type=open_session stdout {{ _motd_file_path }}
|
||||||
|
loop:
|
||||||
|
- "{{ _motd_pam_login_file_path }}"
|
||||||
|
- "{{ _motd_pam_sshd_file_path }}"
|
||||||
|
...
|
22
tasks/disable_default_motd.yml
Normal file
22
tasks/disable_default_motd.yml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
---
|
||||||
|
- name: disable_default_motd | Get stats of {{ _motd_sshd_config_file_path }}
|
||||||
|
stat:
|
||||||
|
path: "{{ _motd_sshd_config_file_path }}"
|
||||||
|
register: _motd_sshd_config_file_stat
|
||||||
|
|
||||||
|
- name: disable_default_motd | Ensure PrintMotd is set to "no" in {{ _motd_sshd_config_file_path }}
|
||||||
|
lineinfile:
|
||||||
|
path: "{{ _motd_sshd_config_file_path }}"
|
||||||
|
regexp: "^PrintMotd "
|
||||||
|
line: PrintMotd no
|
||||||
|
when: _motd_sshd_config_file_stat.stat.exists
|
||||||
|
|
||||||
|
- name: disable_default_motd | Comment out pam_motd in pam
|
||||||
|
replace:
|
||||||
|
path: "{{ item }}"
|
||||||
|
regexp: '^(session\s+optional\s+pam_motd.so\s+.*)'
|
||||||
|
replace: '# \1'
|
||||||
|
loop:
|
||||||
|
- "{{ _motd_pam_login_file_path }}"
|
||||||
|
- "{{ _motd_pam_sshd_file_path }}"
|
||||||
|
...
|
@ -1,58 +1,7 @@
|
|||||||
---
|
---
|
||||||
- block:
|
- name: include_tasks disable_default_motd.yml if motd_disable_default_motd is True
|
||||||
- name: Get stats of {{ _motd_sshd_config_file_path }}
|
include_tasks: disable_default_motd.yml
|
||||||
stat:
|
|
||||||
path: "{{ _motd_sshd_config_file_path }}"
|
|
||||||
register: _motd_sshd_config_file_stat
|
|
||||||
|
|
||||||
- name: Ensure PrintMotd is set to "no" in {{ _motd_sshd_config_file_path }}
|
|
||||||
lineinfile:
|
|
||||||
path: "{{ _motd_sshd_config_file_path }}"
|
|
||||||
regexp: "^PrintMotd "
|
|
||||||
line: PrintMotd no
|
|
||||||
when: _motd_sshd_config_file_stat.stat.exists
|
|
||||||
|
|
||||||
- name: Comment out pam_motd in pam
|
|
||||||
replace:
|
|
||||||
path: "{{ item }}"
|
|
||||||
regexp: '^(session\s+optional\s+pam_motd.so\s+.*)'
|
|
||||||
replace: '# \1'
|
|
||||||
loop:
|
|
||||||
- "{{ _motd_pam_login_file_path }}"
|
|
||||||
- "{{ _motd_pam_sshd_file_path }}"
|
|
||||||
when: motd_disable_default_motd|bool
|
when: motd_disable_default_motd|bool
|
||||||
|
|
||||||
- name: Apply template {{ motd_banner_template }} on {{ _motd_banner_file_path }}
|
- include_tasks: configure_motd.yml
|
||||||
copy:
|
...
|
||||||
content: "{{ motd_banner_template_prepend + _motd_banner_template_content + motd_banner_template_append }}"
|
|
||||||
dest: "{{ _motd_banner_file_path }}"
|
|
||||||
owner: root
|
|
||||||
group: root
|
|
||||||
mode: '0644'
|
|
||||||
when: motd_banner_template
|
|
||||||
|
|
||||||
- name: Ensure line "Banner {{ _motd_banner_file_path }}" is {{ _motd_banner_state }} in {{ _motd_sshd_config_file_path }}
|
|
||||||
lineinfile:
|
|
||||||
path: "{{ _motd_sshd_config_file_path }}"
|
|
||||||
regexp: "^(#?)Banner "
|
|
||||||
line: Banner {{ _motd_banner_file_path }}
|
|
||||||
state: "{{ _motd_banner_state }}"
|
|
||||||
notify: Restart sshd
|
|
||||||
|
|
||||||
- name: Apply template {{ motd_template }} on {{ _motd_file_path }}
|
|
||||||
copy:
|
|
||||||
content: "{{ motd_template_prepend + _motd_template_content + motd_template_append }}"
|
|
||||||
dest: "{{ _motd_file_path }}"
|
|
||||||
owner: root
|
|
||||||
group: root
|
|
||||||
mode: '0755'
|
|
||||||
tags:
|
|
||||||
- molecule-idempotence-notest
|
|
||||||
|
|
||||||
- name: Add pam_exec {{ _motd_file_path }} in pam
|
|
||||||
lineinfile:
|
|
||||||
path: "{{ item }}"
|
|
||||||
line: session optional pam_exec.so type=open_session stdout {{ _motd_file_path }}
|
|
||||||
loop:
|
|
||||||
- "{{ _motd_pam_login_file_path }}"
|
|
||||||
- "{{ _motd_pam_sshd_file_path }}"
|
|
||||||
|
@ -2,10 +2,6 @@
|
|||||||
_motd_sshd_config_file_path: /etc/ssh/sshd_config
|
_motd_sshd_config_file_path: /etc/ssh/sshd_config
|
||||||
_motd_pam_login_file_path: /etc/pam.d/login
|
_motd_pam_login_file_path: /etc/pam.d/login
|
||||||
_motd_pam_sshd_file_path: /etc/pam.d/sshd
|
_motd_pam_sshd_file_path: /etc/pam.d/sshd
|
||||||
_motd_banner_file_path: /etc/banner
|
|
||||||
_motd_banner_state: "{{ 'present' if motd_banner_template else 'absent' }}"
|
|
||||||
_motd_file_path: /usr/local/bin/dynmotd
|
_motd_file_path: /usr/local/bin/dynmotd
|
||||||
_motd_lookup_method: "{{ 'url' if motd_template is match('http(s)?:\/\/') else 'template' }}"
|
_motd_lookup_method: "{{ 'url' if motd_template is match('http(s)?:\/\/') else 'template' }}"
|
||||||
_motd_template_content: "{{ lookup(_motd_lookup_method, motd_template, split_lines=False, username=motd_template_username, password=motd_template_password) }}"
|
_motd_template_content: "{{ lookup(_motd_lookup_method, motd_template, split_lines=False, username=motd_template_username, password=motd_template_password) }}"
|
||||||
_motd_banner_lookup_method: "{{ 'url' if motd_banner_template is match('http(s)?:\/\/') else 'template' }}"
|
|
||||||
_motd_banner_template_content: "{{ lookup(_motd_banner_lookup_method, motd_banner_template, split_lines=False, username=motd_banner_template_username, password=motd_banner_template_password) }}"
|
|
||||||
|
Reference in New Issue
Block a user