Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
8c21123d4f | |||
8382c9f3f3 | |||
eb57d613dc | |||
dc8567c979 | |||
e797037846 | |||
92cb5bf55e | |||
9770e5d43c | |||
cf7e3da48e |
@ -2,6 +2,7 @@
|
||||
exclude_paths:
|
||||
- molecule/
|
||||
- .pre-commit-config.yaml
|
||||
- .github/
|
||||
|
||||
parseable: true
|
||||
|
||||
|
3
.github/workflows/galaxy.yml
vendored
3
.github/workflows/galaxy.yml
vendored
@ -10,6 +10,7 @@ jobs:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: galaxy
|
||||
uses: robertdebock/galaxy-action@1.1.1
|
||||
uses: robertdebock/galaxy-action@1.2.1
|
||||
with:
|
||||
galaxy_api_key: ${{ secrets.galaxy_api_key }}
|
||||
git_branch: main
|
||||
|
50
.github/workflows/molecule.yml
vendored
50
.github/workflows/molecule.yml
vendored
@ -8,43 +8,75 @@ on: # yamllint disable-line rule:truthy
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
setup:
|
||||
name: Setup scenarios matrix
|
||||
runs-on: ubuntu-22.04
|
||||
outputs:
|
||||
scenarios: ${{ steps.matrix.outputs.scenarios }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- id: matrix
|
||||
run: |
|
||||
JSON="["
|
||||
|
||||
for s in $(find molecule -mindepth 1 -maxdepth 1 -type d -exec basename "{}" \;); do
|
||||
JSON="${JSON}\"${s}\","
|
||||
done
|
||||
|
||||
JSON="${JSON%?}"
|
||||
JSON="$JSON]"
|
||||
|
||||
echo "::set-output name=scenarios::$(echo $JSON)"
|
||||
|
||||
lint:
|
||||
runs-on: ubuntu-20.04
|
||||
name: Lint
|
||||
needs:
|
||||
- setup
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
path: "${{ github.repository }}"
|
||||
- name: molecule
|
||||
uses: robertdebock/molecule-action@2.6.17
|
||||
uses: robertdebock/molecule-action@4.0.9
|
||||
with:
|
||||
command: lint
|
||||
scenario: ${{ fromJson(needs.setup.outputs.scenarios)[0] }}
|
||||
|
||||
test:
|
||||
name: Scenario "${{ matrix.scenario }}" on ${{ matrix.config.image }}:${{ matrix.config.tag }}
|
||||
needs:
|
||||
- lint
|
||||
runs-on: ubuntu-20.04
|
||||
- setup
|
||||
runs-on: ubuntu-22.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
scenario: ${{ fromJson(needs.setup.outputs.scenarios) }}
|
||||
config:
|
||||
- image: "amazonlinux"
|
||||
tag: "latest"
|
||||
- image: "centos"
|
||||
tag: "8"
|
||||
- name: "redhat"
|
||||
image: "registry.access.redhat.com/ubi8/ubi"
|
||||
tag: "latest"
|
||||
- image: "debian"
|
||||
tag: "11"
|
||||
- image: "debian"
|
||||
tag: "10"
|
||||
- image: "ubuntu"
|
||||
tag: "20.04"
|
||||
tag: "22.04"
|
||||
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
path: "${{ github.repository }}"
|
||||
- name: molecule
|
||||
uses: robertdebock/molecule-action@2.6.17
|
||||
uses: robertdebock/molecule-action@4.0.9
|
||||
with:
|
||||
image: ${{ matrix.config.image }}
|
||||
tag: ${{ matrix.config.tag }}
|
||||
scenario: ${{ matrix.scenario }}
|
||||
env:
|
||||
name: ${{ matrix.config.name }}
|
||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
###VSCode###
|
||||
.vscode
|
||||
###MacOS###
|
||||
.DS_Store
|
||||
|
||||
|
11
README.md
11
README.md
@ -9,9 +9,9 @@
|
||||
|
||||
> :star: Star us on GitHub — it motivates us a lot!
|
||||
|
||||
Install and configure dynamic MOTD and SSH banner
|
||||
Install and configure dynamic MOTD
|
||||
|
||||
This role uses [https://github.com/claranet/motd](https://github.com/claranet/motd) by default to get the banner and the MOTD
|
||||
This role uses [https://github.com/claranet/motd](https://github.com/claranet/motd) by default to get the MOTD
|
||||
|
||||
```
|
||||
System info:
|
||||
@ -35,7 +35,7 @@ Ansible:
|
||||
|
||||
## :warning: Requirements
|
||||
|
||||
Ansible >= 2.9
|
||||
Ansible >= 2.10
|
||||
|
||||
## :zap: Installation
|
||||
|
||||
@ -48,11 +48,6 @@ ansible-galaxy install claranet.motd
|
||||
Variable | Default value | Description
|
||||
-----------------------------|------------------------------------------------------------------------|----------------------------------------------------------------
|
||||
motd_disable_default_motd | true | Disable system default MOTD (/etc/motd)
|
||||
motd_banner_template | https://raw.githubusercontent.com/claranet/motd/master/banner | SSH banner template<br>Can be a URL, a local template or `null`
|
||||
motd_banner_template_prepend | "" | Prepend raw content to `motd_banner_template`
|
||||
motd_banner_template_append | "" | Append raw content to `motd_banner_template`
|
||||
motd_banner_template_username| {{ motd_template_username }} | Used when `motd_banner_template` is an URL
|
||||
motd_banner_template_password| {{ motd_template_password }} | Used when `motd_banner_template` is an URL
|
||||
motd_template | https://raw.githubusercontent.com/claranet/motd/master/scripts/00-basic| Dynmaic MOTD template<br>Can be a URL or a local template
|
||||
motd_template_prepend | "" | Prepend raw content to `motd_template`
|
||||
motd_template_append | See [defaults/main.yml](defaults/main.yml) | Append raw content to `motd_template`
|
||||
|
@ -1,9 +1,6 @@
|
||||
---
|
||||
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_banner_template_prepend: ""
|
||||
motd_banner_template_append: ""
|
||||
motd_template_prepend: ""
|
||||
motd_template_append: |
|
||||
|
||||
@ -13,5 +10,3 @@ motd_template_append: |
|
||||
|
||||
motd_template_username: ""
|
||||
motd_template_password: ""
|
||||
motd_banner_template_username: "{{ motd_template_username }}"
|
||||
motd_banner_template_password: "{{ motd_template_password }}"
|
||||
|
@ -1,4 +1,4 @@
|
||||
- name: Restart sshd
|
||||
service:
|
||||
ansible.builtin.service:
|
||||
name: sshd
|
||||
state: restarted
|
||||
|
@ -7,7 +7,7 @@ galaxy_info:
|
||||
|
||||
license: "MPL2"
|
||||
|
||||
min_ansible_version: 2.9
|
||||
min_ansible_version: "2.10"
|
||||
|
||||
galaxy_tags: ['claranet', 'motd', 'system', 'dynmotd', 'dynamic']
|
||||
|
||||
|
@ -14,8 +14,11 @@ ENV {{ var }} {{ value }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python3 sudo bash ca-certificates iproute2 systemd && apt-get clean; \
|
||||
elif [ $(command -v yum) ]; then yum install -y python3 sudo bash iproute systemd firewalld initscripts; \
|
||||
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml iproute2 && zypper clean -a; \
|
||||
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \
|
||||
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates iproute2 && xbps-remove -O; fi
|
||||
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python3 sudo bash ca-certificates iproute2 systemd wget && apt-get clean; \
|
||||
elif [ $(command -v yum) ]; then yum install -y python3 sudo bash iproute systemd initscripts wget; \
|
||||
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml iproute2 wget && zypper clean -a; \
|
||||
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates wget; \
|
||||
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates iproute2 wget && xbps-remove -O; fi
|
||||
|
||||
RUN wget -O /usr/bin/systemctl https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl3.py && \
|
||||
chmod +x /usr/bin/systemctl
|
||||
|
@ -3,7 +3,6 @@
|
||||
hosts: all
|
||||
roles:
|
||||
- role: claranet.motd
|
||||
motd_banner_template: null
|
||||
|
||||
pre_tasks:
|
||||
- name: "Update APT cache"
|
||||
|
@ -6,7 +6,9 @@ driver:
|
||||
name: docker
|
||||
|
||||
platforms:
|
||||
- name: claranet_motd_${image:-debian}-${tag:-latest}
|
||||
# On "${name:-${image:-debian}", the last brace does not miss, it works like that...
|
||||
# The env var "name" should be used when the image variable refers to a full registry path like registry.access.redhat.com/ubi8/ubi
|
||||
- name: claranet_motd_${name:-${image:-debian}-${tag:-latest}-${scenario:-default}
|
||||
image: ${image:-debian}:${tag:-latest}
|
||||
privileged: true
|
||||
tty: true
|
||||
|
@ -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}"
|
||||
|
||||
|
||||
def test_banner_file(host):
|
||||
file = host.file("/etc/banner")
|
||||
assert not file.exists
|
||||
|
||||
|
||||
def test_motd_file(host):
|
||||
file = host.file(motd_file_path)
|
||||
assert file.exists
|
||||
|
@ -1,18 +0,0 @@
|
||||
---
|
||||
- name: configure_banner | Apply template {{ motd_banner_template }} on {{ _motd_banner_file_path }}
|
||||
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 != None and motd_banner_template|length>0
|
||||
|
||||
- name: configure_banner | 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
|
||||
...
|
@ -1,19 +0,0 @@
|
||||
---
|
||||
- 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 }}"
|
||||
...
|
@ -1,18 +1,18 @@
|
||||
---
|
||||
- name: disable_default_motd | Get stats of {{ _motd_sshd_config_file_path }}
|
||||
stat:
|
||||
ansible.builtin.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:
|
||||
ansible.builtin.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:
|
||||
ansible.builtin.replace:
|
||||
path: "{{ item }}"
|
||||
regexp: '^(session\s+optional\s+pam_motd.so\s+.*)'
|
||||
replace: '# \1'
|
||||
|
@ -1,9 +1,23 @@
|
||||
---
|
||||
- include_tasks: configure_banner.yml
|
||||
|
||||
- name: include_tasks disable_default_motd.yml if motd_disable_default_motd is True
|
||||
include_tasks: disable_default_motd.yml
|
||||
- name: Include disable_default_motd.yml if motd_disable_default_motd is True
|
||||
ansible.builtin.include_tasks: disable_default_motd.yml
|
||||
when: motd_disable_default_motd|bool
|
||||
|
||||
- include_tasks: configure_motd.yml
|
||||
- name: configure_motd | Apply template {{ motd_template }} on {{ _motd_file_path }}
|
||||
ansible.builtin.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
|
||||
ansible.builtin.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_pam_login_file_path: /etc/pam.d/login
|
||||
_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_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_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