Compare commits
25 Commits
Author | SHA1 | Date | |
---|---|---|---|
824e44cceb | |||
f9177a912f | |||
![]() |
960cc9e72a | ||
![]() |
f5083595f0 | ||
![]() |
831f658f60 | ||
![]() |
8ce4376c87 | ||
![]() |
cc928916a5 | ||
![]() |
4249473328 | ||
![]() |
9cf80214ee | ||
![]() |
68c3f15171 | ||
![]() |
7c53a18c21 | ||
![]() |
8eb3096a5e | ||
![]() |
eaff8d03a5 | ||
![]() |
28a61e55fa | ||
![]() |
b2ad104eec | ||
![]() |
8c21123d4f | ||
![]() |
8382c9f3f3 | ||
![]() |
eb57d613dc | ||
![]() |
dc8567c979 | ||
![]() |
e797037846 | ||
![]() |
92cb5bf55e | ||
![]() |
9770e5d43c | ||
![]() |
cf7e3da48e | ||
![]() |
dbf4d327cf | ||
![]() |
6a42daba46 |
108
.ansible-lint
108
.ansible-lint
@ -2,66 +2,65 @@
|
|||||||
exclude_paths:
|
exclude_paths:
|
||||||
- molecule/
|
- molecule/
|
||||||
- .pre-commit-config.yaml
|
- .pre-commit-config.yaml
|
||||||
|
- .github/
|
||||||
|
|
||||||
parseable: true
|
parseable: true
|
||||||
|
|
||||||
use_default_rules: true
|
use_default_rules: true
|
||||||
|
|
||||||
enable_list:
|
enable_list:
|
||||||
command-shell: # Specific to use of command and shell modules
|
# Specific to use of command and shell modules
|
||||||
- command-instead-of-module
|
- command-instead-of-module
|
||||||
- command-instead-of-shell
|
- command-instead-of-shell
|
||||||
- deprecated-command-syntax
|
- deprecated-command-syntax
|
||||||
- inline-env-var
|
- inline-env-var
|
||||||
- no-changed-when
|
- no-changed-when
|
||||||
- risky-shell-pipe
|
- risky-shell-pipe
|
||||||
core: # Related to internal implementation of the linter
|
# Related to internal implementation of the linter
|
||||||
- internal-error
|
- internal-error
|
||||||
- load-failure
|
- load-failure
|
||||||
- parser-error
|
- parser-error
|
||||||
- syntax-check
|
- syntax-check
|
||||||
deprecations: # Indicate use of features that are removed from Ansible
|
# Indicate use of features that are removed from Ansible
|
||||||
- deprecated-bare-vars
|
- deprecated-bare-vars
|
||||||
- deprecated-command-syntax
|
- deprecated-command-syntax
|
||||||
- deprecated-local-action
|
- deprecated-local-action
|
||||||
- deprecated-module
|
- deprecated-module
|
||||||
- no-jinja-when
|
- no-jinja-when
|
||||||
- role-name
|
- role-name
|
||||||
formatting: # Related to code-style
|
# Related to code-style
|
||||||
- no-jinja-nesting
|
- no-jinja-nesting
|
||||||
- no-tabs
|
- no-tabs
|
||||||
- playbook-extension
|
- playbook-extension
|
||||||
- risky-octal
|
- risky-octal
|
||||||
- var-spacing
|
- var-spacing
|
||||||
- yaml
|
- yaml
|
||||||
idempotency: # Possible indication that consequent runs would produce different results
|
# Possible indication that consequent runs would produce different results
|
||||||
- git-latest
|
- git-latest
|
||||||
- hg-latest
|
- hg-latest
|
||||||
- no-changed-when
|
- no-changed-when
|
||||||
- package-latest
|
- package-latest
|
||||||
idiom: # Anti-pattern detected, likely to cause undesired behavior
|
# Anti-pattern detected, likely to cause undesired behavior
|
||||||
- command-instead-of-module
|
- command-instead-of-module
|
||||||
- command-instead-of-shell
|
- command-instead-of-shell
|
||||||
- empty-string-compare
|
- empty-string-compare
|
||||||
- inline-env-var
|
- inline-env-var
|
||||||
- literal-compare
|
- literal-compare
|
||||||
- no-handler
|
- no-handler
|
||||||
- no-loop-var-prefix
|
- no-loop-var-prefix
|
||||||
- no-relative-paths
|
- no-relative-paths
|
||||||
- unnamed-task
|
- unnamed-task
|
||||||
- var-naming
|
- var-naming
|
||||||
metadata: # Invalid metadata, likely related to galaxy, collections or roles
|
# Invalid metadata, likely related to galaxy, collections or roles
|
||||||
- meta-incorrect
|
- meta-incorrect
|
||||||
- meta-no-tags
|
- meta-no-tags
|
||||||
- meta-video-links
|
- meta-video-links
|
||||||
- role-name
|
- role-name
|
||||||
unpredictability:
|
- ignore-errors
|
||||||
- ignore-errors
|
- partial-become
|
||||||
- partial-become
|
- syntax-check
|
||||||
unskippable:
|
# External linter which will also produce its own rule codes.
|
||||||
- syntax-check
|
- yaml
|
||||||
yaml: # External linter which will also produce its own rule codes.
|
|
||||||
- yaml
|
|
||||||
|
|
||||||
warn_list:
|
warn_list:
|
||||||
- experimental # all rules tagged as experimental
|
- experimental # all rules tagged as experimental
|
||||||
@ -70,5 +69,6 @@ warn_list:
|
|||||||
|
|
||||||
skip_list:
|
skip_list:
|
||||||
- role-name # BUG
|
- role-name # BUG
|
||||||
|
- name[casing]
|
||||||
|
|
||||||
verbosity: 1
|
verbosity: 1
|
||||||
|
3
.github/workflows/galaxy.yml
vendored
3
.github/workflows/galaxy.yml
vendored
@ -10,6 +10,7 @@ jobs:
|
|||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
steps:
|
steps:
|
||||||
- name: galaxy
|
- name: galaxy
|
||||||
uses: robertdebock/galaxy-action@1.1.1
|
uses: robertdebock/galaxy-action@1.2.1
|
||||||
with:
|
with:
|
||||||
galaxy_api_key: ${{ secrets.galaxy_api_key }}
|
galaxy_api_key: ${{ secrets.galaxy_api_key }}
|
||||||
|
git_branch: main
|
||||||
|
60
.github/workflows/molecule.yml
vendored
60
.github/workflows/molecule.yml
vendored
@ -1,50 +1,82 @@
|
|||||||
---
|
---
|
||||||
name: Ansible Molecule
|
name: Ansible Molecule
|
||||||
|
on: # yamllint disable-line rule:truthy
|
||||||
on: # yamllint disable-line rule:truthy
|
|
||||||
push:
|
push:
|
||||||
tags_ignore:
|
tags_ignore:
|
||||||
- '*'
|
- '*'
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
jobs:
|
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:
|
lint:
|
||||||
runs-on: ubuntu-20.04
|
name: Lint
|
||||||
|
needs:
|
||||||
|
- setup
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
- name: checkout
|
- name: checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
path: "${{ github.repository }}"
|
path: "${{ github.repository }}"
|
||||||
- name: molecule
|
- name: Run ansible lint
|
||||||
uses: robertdebock/molecule-action@2.6.17
|
uses: ansible/ansible-lint-action@main
|
||||||
with:
|
with:
|
||||||
command: lint
|
path: "."
|
||||||
|
|
||||||
test:
|
test:
|
||||||
|
name: Scenario "${{ matrix.scenario }}" on ${{ matrix.config.image }}:${{ matrix.config.tag }}
|
||||||
needs:
|
needs:
|
||||||
- lint
|
- lint
|
||||||
|
- setup
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
|
scenario: ${{ fromJson(needs.setup.outputs.scenarios) }}
|
||||||
config:
|
config:
|
||||||
- image: "amazonlinux"
|
- image: "amazonlinux"
|
||||||
tag: "latest"
|
tag: "latest"
|
||||||
- image: "centos"
|
- name: "redhat"
|
||||||
tag: "8"
|
image: "registry.access.redhat.com/ubi8/ubi"
|
||||||
|
tag: "latest"
|
||||||
|
- image: "debian"
|
||||||
|
tag: "12"
|
||||||
- image: "debian"
|
- image: "debian"
|
||||||
tag: "11"
|
tag: "11"
|
||||||
- image: "debian"
|
- image: "debian"
|
||||||
tag: "10"
|
tag: "10"
|
||||||
- image: "ubuntu"
|
- image: "ubuntu"
|
||||||
tag: "20.04"
|
tag: "22.04"
|
||||||
|
- image: ubuntu
|
||||||
|
tag: "24.04"
|
||||||
steps:
|
steps:
|
||||||
- name: checkout
|
- name: checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
path: "${{ github.repository }}"
|
path: "${{ github.repository }}"
|
||||||
- name: molecule
|
- name: molecule
|
||||||
uses: robertdebock/molecule-action@2.6.17
|
uses: gofrolist/molecule-action@v2
|
||||||
with:
|
with:
|
||||||
|
# molecule_options: --debug
|
||||||
|
molecule_command: test
|
||||||
|
molecule_args: --scenario-name ${{ matrix.scenario }} -d docker
|
||||||
|
molecule_working_dir: "${{ github.repository }}"
|
||||||
|
env:
|
||||||
image: ${{ matrix.config.image }}
|
image: ${{ matrix.config.image }}
|
||||||
tag: ${{ matrix.config.tag }}
|
tag: ${{ matrix.config.tag }}
|
||||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
|||||||
|
###VSCode###
|
||||||
|
.vscode
|
||||||
###MacOS###
|
###MacOS###
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
31
README.md
31
README.md
@ -1,25 +1,15 @@
|
|||||||
# Ansible role - motd
|
# Ansible role - motd
|
||||||
[](https://www.claranet.fr/)
|
|
||||||
[](LICENSE)
|
|
||||||
[](https://github.com/claranet/ansible-role-motd/releases)
|
|
||||||
[](https://github.com/claranet/ansible-role-motd/actions?query=workflow%3A%22Ansible+Molecule%22)
|
|
||||||
[](https://github.com/ansible/ansible)
|
|
||||||
[](https://galaxy.ansible.com/claranet/motd)
|
|
||||||
|
|
||||||
|
Install and configure dynamic MOTD
|
||||||
|
|
||||||
> :star: Star us on GitHub — it motivates us a lot!
|
This role uses [https://gitea.tips-of-mine.com/Tips-Of-Mine/motd](https://gitea.tips-of-mine.com/Tips-Of-Mine/motd) by default to get the MOTD
|
||||||
|
|
||||||
Install and configure dynamic MOTD and SSH banner
|
|
||||||
|
|
||||||
This role uses [https://github.com/claranet/motd](https://github.com/claranet/motd) by default to get the banner and the MOTD
|
|
||||||
|
|
||||||
```
|
```
|
||||||
System info:
|
System info:
|
||||||
Hostname·········: claranet_motd_ubuntu-20.04
|
Hostname·········: tips-of-mine_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 12 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)
|
||||||
CPU··············: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz (4 vCPU)
|
CPU··············: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz (4 vCPU)
|
||||||
@ -36,12 +26,12 @@ Ansible:
|
|||||||
|
|
||||||
## :warning: Requirements
|
## :warning: Requirements
|
||||||
|
|
||||||
Ansible >= 2.9
|
Ansible >= 2.10
|
||||||
|
|
||||||
## :zap: Installation
|
## :zap: Installation
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
ansible-galaxy install claranet.motd
|
ansible-galaxy install tips-of-mine.motd
|
||||||
```
|
```
|
||||||
|
|
||||||
## :gear: Role variables
|
## :gear: Role variables
|
||||||
@ -49,12 +39,7 @@ ansible-galaxy install claranet.motd
|
|||||||
Variable | Default value | Description
|
Variable | Default value | Description
|
||||||
-----------------------------|------------------------------------------------------------------------|----------------------------------------------------------------
|
-----------------------------|------------------------------------------------------------------------|----------------------------------------------------------------
|
||||||
motd_disable_default_motd | true | Disable system default MOTD (/etc/motd)
|
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_template | https://gitea.tips-of-mine.com/Tips-Of-Mine/motd/scripts/00-basic | Dynmaic MOTD template<br>Can be a URL or a local template
|
||||||
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_prepend | "" | Prepend raw content to `motd_template`
|
||||||
motd_template_append | See [defaults/main.yml](defaults/main.yml) | Append raw content to `motd_template`
|
motd_template_append | See [defaults/main.yml](defaults/main.yml) | Append raw content to `motd_template`
|
||||||
motd_template_username | "" | Used when `motd_template` is an URL
|
motd_template_username | "" | Used when `motd_template` is an URL
|
||||||
@ -66,7 +51,7 @@ motd_template_password | ""
|
|||||||
---
|
---
|
||||||
- hosts: all
|
- hosts: all
|
||||||
roles:
|
roles:
|
||||||
- role: claranet.motd
|
- role: tips-of-mine.motd
|
||||||
motd_template: "{{ playbook_dir }}/templates/dynmotd.j2"
|
motd_template: "{{ playbook_dir }}/templates/dynmotd.j2"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -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://gitea.tips-of-mine.com/Tips-Of-Mine/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 }}"
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
- name: Restart sshd
|
- name: Restart sshd
|
||||||
service:
|
ansible.builtin.service:
|
||||||
name: sshd
|
name: sshd
|
||||||
state: restarted
|
state: restarted
|
||||||
|
@ -7,7 +7,7 @@ galaxy_info:
|
|||||||
|
|
||||||
license: "MPL2"
|
license: "MPL2"
|
||||||
|
|
||||||
min_ansible_version: 2.9
|
min_ansible_version: "2.10"
|
||||||
|
|
||||||
galaxy_tags: ['claranet', 'motd', 'system', 'dynmotd', 'dynamic']
|
galaxy_tags: ['claranet', 'motd', 'system', 'dynmotd', 'dynamic']
|
||||||
|
|
||||||
|
@ -14,8 +14,11 @@ ENV {{ var }} {{ value }}
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% 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; \
|
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 firewalld initscripts; \
|
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 && zypper clean -a; \
|
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; \
|
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 && xbps-remove -O; fi
|
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,15 +3,14 @@
|
|||||||
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"
|
||||||
apt:
|
ansible.builtin.apt:
|
||||||
update_cache: true
|
update_cache: true
|
||||||
when:
|
when:
|
||||||
- ansible_pkg_mgr == "apt"
|
- ansible_pkg_mgr == "apt"
|
||||||
|
|
||||||
- name: Install sshd
|
- name: Install sshd
|
||||||
package:
|
ansible.builtin.package:
|
||||||
name: openssh-server
|
name: openssh-server
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
---
|
---
|
||||||
dependency:
|
dependency:
|
||||||
name: galaxy
|
name: shell
|
||||||
|
command: python3 -m pip install pytest-testinfra
|
||||||
|
|
||||||
driver:
|
driver:
|
||||||
name: docker
|
name: docker
|
||||||
|
|
||||||
platforms:
|
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 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}
|
image: ${image:-debian}:${tag:-latest}
|
||||||
privileged: true
|
privileged: true
|
||||||
tty: true
|
tty: true
|
||||||
@ -24,13 +27,14 @@ provisioner:
|
|||||||
name: ansible
|
name: ansible
|
||||||
env:
|
env:
|
||||||
ANSIBLE_FORCE_COLOR: "true"
|
ANSIBLE_FORCE_COLOR: "true"
|
||||||
|
ANSIBLE_LOAD_CALLBACK_PLUGINS: "true"
|
||||||
|
ANSIBLE_STDOUT_CALLBACK: "ansible.posix.debug"
|
||||||
|
ANSIBLE_CALLBACKS_ENABLED: "ansible.posix.profile_tasks"
|
||||||
options:
|
options:
|
||||||
v: true
|
v: true
|
||||||
|
|
||||||
verifier:
|
verifier:
|
||||||
name: testinfra
|
name: testinfra
|
||||||
lint:
|
|
||||||
name: flake8
|
|
||||||
options:
|
options:
|
||||||
verbose: true
|
verbose: true
|
||||||
s: true
|
s: 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}"
|
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
|
||||||
|
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 }}
|
||||||
|
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 }}
|
||||||
|
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
|
||||||
|
ansible.builtin.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,46 +1,10 @@
|
|||||||
---
|
---
|
||||||
- block:
|
- name: Include disable_default_motd.yml if motd_disable_default_motd is True
|
||||||
- name: Get stats of {{ _motd_sshd_config_file_path }}
|
ansible.builtin.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 }}
|
- name: "Configure_motd | Apply template {{ motd_template + ' in ' + _motd_file_path }}"
|
||||||
copy:
|
ansible.builtin.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 }}"
|
content: "{{ motd_template_prepend + _motd_template_content + motd_template_append }}"
|
||||||
dest: "{{ _motd_file_path }}"
|
dest: "{{ _motd_file_path }}"
|
||||||
owner: root
|
owner: root
|
||||||
@ -49,10 +13,11 @@
|
|||||||
tags:
|
tags:
|
||||||
- molecule-idempotence-notest
|
- molecule-idempotence-notest
|
||||||
|
|
||||||
- name: Add pam_exec {{ _motd_file_path }} in pam
|
- name: Configure_motd | Add in pam pam_exec {{ _motd_file_path }}
|
||||||
lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: "{{ item }}"
|
path: "{{ item }}"
|
||||||
line: session optional pam_exec.so type=open_session stdout {{ _motd_file_path }}
|
line: session optional pam_exec.so type=open_session stdout {{ _motd_file_path }}
|
||||||
loop:
|
loop:
|
||||||
- "{{ _motd_pam_login_file_path }}"
|
- "{{ _motd_pam_login_file_path }}"
|
||||||
- "{{ _motd_pam_sshd_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) }}"
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user