Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Add molecule stuff #27

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a3bcd81
Add molecule stuff
Melkor333 Jan 13, 2023
2f6fa83
Fix linting errors
Melkor333 Jan 13, 2023
1bbb914
A lot of changes, run per distribution
Melkor333 Jan 13, 2023
865e2fa
Use full prepare from beat
Melkor333 Jan 13, 2023
0cd36cf
Molecule ran per image
Melkor333 Jan 16, 2023
4b7ac88
github workflow: Don't run molecule twice
Melkor333 Jan 16, 2023
0bca99f
ansible-lint remove overfluous nl
Melkor333 Jan 16, 2023
3fd9e0c
molecule: Use hostname-prefix for playbook selection
Melkor333 Jan 16, 2023
18d34ef
Molecule: Remove ansible install in prepare
Melkor333 Jan 16, 2023
a908414
Remove more unnecessary preparation and fix Debian prep file
Melkor333 Jan 16, 2023
ac2a49f
Molecule: Various small fixes
Melkor333 Jan 16, 2023
5fd6791
remove linting from molecule and install rsync
Melkor333 Jan 18, 2023
ffa43c8
Molecule worflow: install rsync with sudo
Melkor333 Jan 18, 2023
d8c6312
Molecule: Fix variable namings
Melkor333 Jan 18, 2023
cab7df3
Molecule: no hos_prefix and use privileged mode
Melkor333 Jan 18, 2023
092fb1d
Use pre_build_image
Melkor333 Jan 18, 2023
e131270
Use updated molecule action
Melkor333 Jan 18, 2023
dd88f75
Molecule: Remove unnecessary rsync install
Melkor333 Jan 19, 2023
a44c559
Molecule: Add very basic readme info
Melkor333 Jan 20, 2023
d5c47c0
feat(tests): make maintenance_10_linux idempotent
fujexo Feb 10, 2023
bcc6363
yum check-update fails when error status is wrong
Melkor333 Feb 8, 2023
d81e753
feat(molecule): make debian green
fujexo Feb 14, 2023
4a82006
Fix typo in example ansible.cfg
s3lph Jan 13, 2023
2bfcb62
fix(10-034): use actual size on disk to account for sparse files
s3lph Jan 10, 2023
bd0bad4
fix(10-034): only get necessary info from stat
s3lph Jan 11, 2023
9605ae8
feat(12-ubuntu): implement ubuntu checklist
fujexo Jan 25, 2023
8b4e690
fix(12-ubuntu): use the correct `taskid` for the template task exclude
fujexo Jan 27, 2023
6decdcb
fix(12-ubuntu): fix sorting and comments of the defaults
fujexo Jan 27, 2023
f6b1111
feat(report): implement tristate checklist and show indeterminate sta…
s3lph Jan 27, 2023
121f094
feat(molecule): make CentOS green
fujexo Feb 20, 2023
3e8ed4f
fix(10-034): jinja error in debug.
s3lph Feb 10, 2023
416b6c5
fix(10-042): Limit user lookups to "local" NSS passwd databases
s3lph Jan 18, 2023
baca8a7
fix(10-042): make changes in audit_ssh_authorizedkeys compatible with…
s3lph Jan 30, 2023
a02593e
feat(10-042): introduce a second param ignore_nss_backends that silen…
s3lph Feb 10, 2023
ae0b22d
feat(10-042): actually use ignore_nss_backends in the maintenance_10_…
s3lph Feb 10, 2023
07f9777
feat(molecule): update molecule action
fujexo Feb 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
name: Ansible Molecule

on:
pull_request:

jobs:
test:
runs-on: ubuntu-20.04
strategy:
matrix:
config:
- image: "debian"
tag: "bullseye"
- image: "debian"
tag: "buster"
- image: "centos"
tag: "7"
- image: "centos"
namespace: "quay.io/centos/"
tag: "stream8"
- image: "centos"
namespace: "quay.io/centos/"
tag: "stream9"
- image: "leap"
namespace: "registry.opensuse.org/opensuse/"
tag: "15"
fail-fast: false
steps:
- name: checkout
uses: actions/checkout@v3
with:
path: "${{ github.repository }}"
- name: molecule
uses: robertdebock/[email protected]
with:
image: ${{ matrix.config.image }}
tag: ${{ matrix.config.tag }}
namespace: ${{ matrix.config.namespace }}
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Check out `roles/maintenance_*/defaults/main.yml` to see which options can be ov
[defaults]
display_skipped_hosts=no
display_ok_hosts=no
callbacks_whitelist=adfinis.maintenance.report
callback_whitelist=adfinis.maintenance.report
callbacks_enabled=adfinis.maintenance.report
duplicate_dict_key=ignore
inject_facts_as_vars=no
Expand Down Expand Up @@ -136,6 +136,14 @@ changed: [debian01.example.org]

There is also a checklist summarising all tasks that were run but finished with either `ok` or `skipped`.

## Molecule Tests

Before testing, create a file `.env.yml` with the infos on the platform you want to test (see the matrix in the [molecule workflow](.github/workflows/molecule.yml) for examples):

``` yaml
image: "debian"
tag: "bullseye"
```

## License

Expand Down
1 change: 1 addition & 0 deletions galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
### REQUIRED
# The namespace of the collection. This can be a company/brand/organization or product namespace under which all
# content lives. May only contain alphanumeric lowercase characters and underscores. Namespaces cannot start with
Expand Down
32 changes: 32 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---

- name: All tasks
hosts: all
gather_facts: true
vars:
maintenance_exclude_tasks:
- 11-020 # Initramfs update
- 10-028 # Hard depends on systemd -> Doesn't work yet with centos
# - 10-039
# - 10-041
# - 10-042
# - 10-051 # TODO: remove these!

tasks:
- name: "Include 10_linux/"
ansible.builtin.include_role:
name: "maintenance_10_linux"

- name: "Include 11_debian/"
ansible.builtin.include_role:
name: "maintenance_11_debian"
when: ansible_facts['os_family'] == "Debian"

- name: "Print os Family"
ansible.builtin.debug:
var: ansible_facts['os_family']

- name: "Include 15_rhel/"
ansible.builtin.include_role:
name: "maintenance_15_rhel"
when: ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == "Suse"
38 changes: 38 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
dependency:
name: galaxy

driver:
name: docker

platforms:
- name: "${image:-debian}-${tag:-10}"
image: "${namespace}${image:-debian}:${tag:-10}"

provisioner:
name: ansible
env:
ANSIBLE_ROLES_PATH: "../../roles"
options:
D: true
config_options:
defaults:
retry_files_enabled: false
callbacks_enabled: "adfinis.maintenance.report"
duplicate_dict_key: ignore
inject_facts_as_vars: false

scenario:
test_sequence:
- dependency
- destroy
- syntax
- create
- prepare
- converge
- side_effect
- idempotence
- destroy

verifier:
name: ansible
11 changes: 11 additions & 0 deletions molecule/default/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---

- name: Prepare hosts
hosts: all
tasks:
- name: Gather facts
ansible.builtin.setup:

- name: Prepare container
ansible.builtin.include_tasks:
file: "prepare/{{ ansible_facts.distribution }}{{ ansible_facts.distribution_major_version }}.yml"
19 changes: 19 additions & 0 deletions molecule/default/prepare/CentOS7.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Install packages
ansible.builtin.yum:
name:
- selinux-policy
- openssh-server
- audit
- sysvinit-tools
- libselinux-python
state: installed

# EL7 delivers Ansible 2.9 throuh EPEL which is too old for
# ansible-collection-maintenance
# To keep effort low, we take the package through pip

- name: Create SSH keys
ansible.builtin.command:
cmd: "ssh-keygen -A"
creates: /etc/ssh/ssh_host_rsa_key
20 changes: 20 additions & 0 deletions molecule/default/prepare/CentOS8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
- name: Install packages
ansible.builtin.yum:
name:
- selinux-policy
- hostname
- openssh-server
- audit
- libselinux-python3
state: installed

- name: Create SSH keys
ansible.builtin.command:
cmd: "ssh-keygen -A"
creates: /etc/ssh/ssh_host_rsa_key

- name: Create wtmp
ansible.builtin.file:
path: /var/log/wtmp
state: file
21 changes: 21 additions & 0 deletions molecule/default/prepare/CentOS9.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- name: Install packages
ansible.builtin.yum:
name:
- selinux-policy
- hostname
- openssh-server
- audit
- postfix
- libselinux-python3
state: installed

- name: Create SSH keys
ansible.builtin.command:
cmd: "ssh-keygen -A"
creates: /etc/ssh/ssh_host_rsa_key

- name: Create wtmp
ansible.builtin.file:
path: /var/log/wtmp
state: file
25 changes: 25 additions & 0 deletions molecule/default/prepare/Debian10.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
- name: Install packages
ansible.builtin.apt:
name:
- openssh-server
- postfix
state: present
update_cache: true

- name: SSH working directory
ansible.builtin.file:
path: /run/sshd
state: directory
mode: 0755
owner: root
group: root

- name: Security repo
ansible.builtin.copy:
content: |
deb http://security.debian.org/debian-security buster/updates main
dest: /etc/apt/sources.list.d/security_debian_org_debian_security.list
mode: "0755"
owner: root
group: root
25 changes: 25 additions & 0 deletions molecule/default/prepare/Debian11.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
- name: Install packages
ansible.builtin.apt:
name:
- openssh-server
- postfix
state: present
update_cache: true

- name: SSH working directory
ansible.builtin.file:
path: /run/sshd
state: directory
mode: 0755
owner: root
group: root

- name: Security repo
ansible.builtin.copy:
content: |
deb http://security.debian.org/debian-security bullseye-security main
dest: /etc/apt/sources.list.d/security_debian_org_debian_security.list
mode: "0755"
owner: root
group: root
35 changes: 35 additions & 0 deletions molecule/default/prepare/openSUSE Leap15.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
- name: Install packages
community.general.zypper:
name:
- python3-pip
- python3-rpm
- hostname
- openssh-server
state: installed
disable_gpg_check: true

# SUSE 12 delivers Ansible 2.9 which is too old for
# ansible-collection-maintenance
# To keep effort low, we take the package through pip

- name: Upgrade pip
ansible.builtin.command:
cmd: "pip3 install --upgrade pip"
creates: /usr/bin/pip3.6

- name: Install Ansible
ansible.builtin.command:
cmd: "pip3.6 install ansible"
creates: /usr/bin/ansible

- name: Create wtmp
ansible.builtin.file:
path: /var/log/wtmp
type: file
state: present

- name: Create SSH keys
ansible.builtin.command:
cmd: "ssh-keygen -A"
creates: /etc/ssh/ssh_host_rsa_key
21 changes: 21 additions & 0 deletions molecule/default/side_effect.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---

- name: All tasks
hosts: all
gather_facts: true

tasks:
- name: "Load distribution version specific tasks"
ansible.builtin.include_tasks:
file: "{{ item }}"
with_first_found:
- "side_effect/{{ ansible_facts.distribution }}{{ ansible_facts.distribution_major_version }}.yml"
- "side_effect/{{ ansible_facts.distribution }}.yml"
- "side_effect/empty.yml"

- name: "10-050: Fix serverlogs address"
ansible.builtin.lineinfile:
path: /etc/aliases
regexp: "^root:"
line: "root: [email protected]"
insertbefore: EOF
12 changes: 12 additions & 0 deletions molecule/default/side_effect/CentOS7.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---

- name: "15-010: Create local repo"
ansible.builtin.copy:
dest: "/etc/yum.repos.d/local.repo"
content: |
[rhel-{{ ansible_facts.distribution_major_version }}-server-x86_64]
name = {{ ansible_facts.distribution_major_version }}-server-x86_64
enabled = 1
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
gpgcheck=0
cost=9001
18 changes: 18 additions & 0 deletions molecule/default/side_effect/CentOS8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---

- name: "15-010: Create local repo"
ansible.builtin.copy:
dest: "/etc/yum.repos.d/local.repo"
content: |
[rhel-{{ ansible_facts.distribution_major_version }}-for-x86_64-baseos-rpms]
name = {{ ansible_facts.distribution_major_version }}-server-x86_64
enabled = 1
mirrorlist=http://mirrorlist.centos.org/?release=$stream&arch=$basearch&repo=BaseOS&infra=$infra
gpgcheck=0
cost=9001
[rhel-{{ ansible_facts.distribution_major_version }}-for-x86_64-appstream-rpms]
name = {{ ansible_facts.distribution_major_version }}-server-x86_64
enabled = 1
mirrorlist=http://mirrorlist.centos.org/?release=$stream&arch=$basearch&repo=AppStream&infra=$infra
gpgcheck=0
cost=9001
19 changes: 19 additions & 0 deletions molecule/default/side_effect/CentOS9.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---

- name: "15-010: Create local repo"
ansible.builtin.copy:
dest: "/etc/yum.repos.d/local.repo"
content: |
[rhel-{{ ansible_facts.distribution_major_version }}-for-x86_64-baseos-rpms]
name = {{ ansible_facts.distribution_major_version }}-server-x86_64
enabled = 1
mirrorlist=https://mirrors.centos.org/metalink?repo=centos-baseos-$stream&arch=$basearch&protocol=https,http
gpgcheck=0
cost=9001
[rhel-{{ ansible_facts.distribution_major_version }}-for-x86_64-appstream-rpms]
name = {{ ansible_facts.distribution_major_version }}-server-x86_64
enabled = 1
mirrorlist=https://mirrors.centos.org/metalink?repo=centos-appstream-$stream&arch=$basearch&protocol=https,http
gpgcheck=0
cost=9001

6 changes: 6 additions & 0 deletions molecule/default/side_effect/Debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---

- name: "11-017: Execute the package upgrade"
ansible.builtin.apt:
update_cache: yes
upgrade: safe
Empty file.
Loading