Compare commits

...

45 Commits

Author SHA1 Message Date
Jeremy Gardais bac335be11 Merge remote-tracking branch 'github/add_molecule' 2021-08-09 17:07:05 +02:00
Paweł Krawczyk e696d9b482
Restore systemd-fedora-latest image 2021-08-09 10:38:07 +01:00
Paweł Krawczyk 40c632734f
Restore systemd-debian-latest image 2021-08-09 10:32:28 +01:00
Paweł Krawczyk 6a491d63f0
Add separate scenario for Archlinux with custom Dockerfile 2021-08-09 10:05:17 +01:00
Paweł Krawczyk ad499e949f
Leave systems that work for now 2021-08-08 23:48:08 +01:00
Paweł Krawczyk a8a41dfc91
Fix syntax 2021-08-08 23:39:52 +01:00
Paweł Krawczyk 0030b9bfcb
Add archlinux platform 2021-08-08 23:37:47 +01:00
Paweł Krawczyk a75f5bc391
Add volumes to all images 2021-08-08 23:27:47 +01:00
Paweł Krawczyk 32c4ab5215
Because we just can't have init in one place... 2021-08-08 23:19:44 +01:00
Paweł Krawczyk c8fd17d52b
Add Debian and Fedora 2021-08-08 22:14:36 +01:00
Paweł Krawczyk 7e31500c36
Fix variable name 2021-08-08 22:14:21 +01:00
Paweł Krawczyk 0669fe1623
Test for key files generated by the role 2021-08-08 21:48:02 +01:00
Paweł Krawczyk a0fd38056a
Adjust test to differences between CentOS and Debian 2021-08-08 21:40:13 +01:00
Paweł Krawczyk d73b5bbc8f
Debug rules prior to verification 2021-08-08 21:27:18 +01:00
Paweł Krawczyk 73bc1c464b
Fix ansible-lint config location 2021-08-08 21:16:06 +01:00
Paweł Krawczyk 95321f21f9
Mute role-name warnings 2021-08-08 21:01:57 +01:00
Paweł Krawczyk 9940f37baa
Mute lint warnings related to testing 2021-08-08 20:55:56 +01:00
Paweł Krawczyk 5e7b20680b
Fix systemd-ubuntu 2021-08-08 20:47:20 +01:00
Paweł Krawczyk 4eb6a5ae3b
Run ubuntu as privileged 2021-08-08 20:09:42 +01:00
Paweł Krawczyk be4f52b728
Use jrei/systemd-ubuntu 2021-08-08 19:43:58 +01:00
Paweł Krawczyk a5aa2c6e4a
Add some actual verification tasks 2021-08-08 19:09:08 +01:00
Paweł Krawczyk a6f7fde29a
Try centos-systemd 2021-08-08 17:59:44 +01:00
Paweł Krawczyk 8bd7607c09
Typo 2021-08-08 15:52:26 +01:00
Paweł Krawczyk 9fabd5a845
Use Molecule provisioned images 2021-08-08 15:41:28 +01:00
Paweł Krawczyk 9fd12fe790
Skip lint for now 2021-08-07 23:37:58 +01:00
Paweł Krawczyk 3b55e70281
Remove empty lines (yamllint) 2021-08-07 23:35:43 +01:00
Paweł Krawczyk 5416e20904
Fix YAML syntax 2021-08-07 23:30:37 +01:00
Paweł Krawczyk 06fecc68b2
Use robertdebock/molecule-action 2021-08-07 23:29:36 +01:00
Paweł Krawczyk da74b7d2b1
Add Debian scenario 2021-08-07 22:40:29 +01:00
Paweł Krawczyk d786479bc1
Try to run with systemd 2021-08-07 14:20:52 +01:00
Paweł Krawczyk 340f4f83e4
Just run on Alpine 2021-08-07 14:15:13 +01:00
Paweł Krawczyk 652863dd97
OS family for CentOS is RedHat 2021-08-07 14:14:39 +01:00
Paweł Krawczyk 85bb753dd4
Use another action 2021-08-07 14:12:13 +01:00
Paweł Krawczyk b96b750f8d
Try centos/systemd 2021-08-07 14:05:10 +01:00
Paweł Krawczyk 811bd11e9d
Do not remove iptables on test instances 2021-08-07 14:01:35 +01:00
Paweł Krawczyk 26eb76412f
Add config for Arch and Alpine 2021-08-07 13:53:23 +01:00
Paweł Krawczyk 574d9c46b8
Disable other images for now 2021-08-07 13:33:10 +01:00
Paweł Krawczyk 06c594f11b
Debug os family detection in GitHub Actions 2021-08-07 13:32:43 +01:00
Paweł Krawczyk 37919bb428
Do not create inventory 2021-08-07 13:28:36 +01:00
Paweł Krawczyk 9dae659fec
Init Ansible dir 2021-08-07 13:06:08 +01:00
Paweł Krawczyk 933cf1df4e
Create inventory file 2021-08-07 13:04:49 +01:00
Paweł Krawczyk 5df70d971f
Try using matrix with action-molecule 2021-08-07 12:44:26 +01:00
Paweł Krawczyk 6084cfce83
Add task names as required by ansible-lint 2021-08-07 12:18:09 +01:00
Paweł Krawczyk 8fad9d75fd
Update cache on package install 2021-08-07 11:47:32 +01:00
Paweł Krawczyk 82270dc5ef
Specify namespace to allow automatic role path resolution in Molecule 2021-08-07 11:41:14 +01:00
14 changed files with 256 additions and 19 deletions

4
.ansible-lint Normal file
View File

@ -0,0 +1,4 @@
skip_list:
- command-instead-of-module
- no-changed-when
- role-name

View File

@ -1,20 +1,23 @@
---
name: Molecule
name: ipr-cnrs.nftables.molecule
on:
push:
branches: [main]
branches: [master]
pull_request:
branches: [main]
branches: [master]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Ansible Molecule
uses: MonolithProjects/action-molecule@v1.4.3
- name: checkout
uses: actions/checkout@v2
with:
path: "${{ github.repository }}"
- name: molecule
uses: robertdebock/molecule-action@2.6.17

View File

@ -4,6 +4,8 @@ dependencies: []
galaxy_info:
author: "Jérémy Gardais"
namespace: ipr-cnrs
role_name: nftables
description: "Manage Nftables rules and packages"
license: WTFPL
company: IPR

View File

@ -0,0 +1,7 @@
FROM archlinux:latest
ENV container=docker
RUN pacman -Sy --noconfirm python
VOLUME ["/sys/fs/cgroup", "/tmp", "/run"]
CMD ["/usr/sbin/init"]

View File

@ -0,0 +1,9 @@
---
- name: Converge
hosts: all
gather_facts: yes
roles:
- role: ipr-cnrs.nftables
nft_debug: true
# can't remove iptables on an instance with docker
nft_old_pkg_manage: false

View File

@ -0,0 +1,19 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: archlinux
image: archlinux:latest
command: /usr/sbin/init
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
tmpfs:
- /run
- /tmp
provisioner:
name: ansible
verifier:
name: ansible

View File

@ -0,0 +1,72 @@
---
# This is an example playbook to execute Ansible tests.
- name: Verify
hosts: all
gather_facts: false
tasks:
- name: check for nftables.d
stat:
path: /etc/nftables.d
register: p
- name: check nftables.d
assert:
that:
- p.stat.exists and p.stat.isdir
- name: check for nftables.conf
stat:
path: /etc/nftables.conf
register: p
- name: check nftables.conf
assert:
that:
- p.stat.exists
- name: check for nftables.conf
stat:
path: /etc/nftables.d/filter-input.nft
register: p
- name: check filter-input.nft
assert:
that:
- p.stat.exists
- name: list rules
command: nft list ruleset
register: nft
- name: debug rules
debug: var=nft
- name: check rules
assert:
that:
# The whole line is:
# type filter hook input priority 0; policy drop;
# However on CentOS will return "priority 0", while Debian will
# show "priority filter"
- '"type filter hook input" in nft.stdout'
- '"type filter hook output" in nft.stdout'
- name: service status - active
command: systemctl is-active nftables.service
register: status
- name: check service status
assert:
that:
- 'status.stdout == "active"'
- name: service status - enabled
command: systemctl is-enabled nftables.service
register: status
- name: check service status
assert:
that:
- 'status.stdout == "enabled"'

View File

@ -1,7 +1,9 @@
---
- name: Converge
hosts: all
gather_facts: yes
roles:
- role: ipr-cnrs.nftables
nft_debug: true
# can't remove iptables on an instance with docker
nft_old_pkg_manage: false

View File

@ -1,11 +1,54 @@
---
dependency:
name: galaxy
lint: |
set -e
yamllint .
ansible-lint
driver:
name: docker
platforms:
- name: instance
image: ubuntu:latest
- name: systemd-ubuntu-latest
image: jrei/systemd-ubuntu:latest
command: /usr/sbin/init
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
tmpfs:
- /run
- /tmp
- name: systemd-centos-latest
image: centos/systemd:latest
command: /usr/sbin/init
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
tmpfs:
- /run
- /tmp
- name: systemd-debian-latest
image: jrei/systemd-debian:latest
command: /sbin/init
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
tmpfs:
- /run
- /tmp
- name: systemd-fedora-latest
image: jrei/systemd-fedora:latest
command: /usr/sbin/init
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
tmpfs:
- /run
- /tmp
provisioner:
name: ansible
verifier:

View File

@ -5,6 +5,68 @@
hosts: all
gather_facts: false
tasks:
- name: Example assertion
- name: check for nftables.d
stat:
path: /etc/nftables.d
register: p
- name: check nftables.d
assert:
that: true
that:
- p.stat.exists and p.stat.isdir
- name: check for nftables.conf
stat:
path: /etc/nftables.conf
register: p
- name: check nftables.conf
assert:
that:
- p.stat.exists
- name: check for nftables.conf
stat:
path: /etc/nftables.d/filter-input.nft
register: p
- name: check filter-input.nft
assert:
that:
- p.stat.exists
- name: list rules
command: nft list ruleset
register: nft
- name: debug rules
debug: var=nft
- name: check rules
assert:
that:
# The whole line is:
# type filter hook input priority 0; policy drop;
# However on CentOS will return "priority 0", while Debian will
# show "priority filter"
- '"type filter hook input" in nft.stdout'
- '"type filter hook output" in nft.stdout'
- name: service status - active
command: systemctl is-active nftables.service
register: status
- name: check service status
assert:
that:
- 'status.stdout == "active"'
- name: service status - enabled
command: systemctl is-enabled nftables.service
register: status
- name: check service status
assert:
that:
- 'status.stdout == "enabled"'

View File

@ -13,7 +13,8 @@
loop_control:
loop_var: groupname
- debug: var=nftables_group_rules
- name: Debug nftables_group_rules
debug: var=nftables_group_rules
when: nft_debug
- name: Import nftables-variables if nft_merged_groups is set
@ -36,7 +37,12 @@
loop_control:
loop_var: varfile
- debug: var=nft_combined_rules
- name: Debug nft_combined_rules
debug: var=nft_combined_rules
when: nft_debug
- name: Debug ansible_os_family
debug: var=ansible_os_family
when: nft_debug
- name: Load specific OS vars for nftables
@ -53,6 +59,7 @@
package:
name: '{{ nft_pkg_list | list }}'
state: '{{ nft_pkg_state }}'
update_cache: true
register: pkg_install_result
until: pkg_install_result is success
when: nft_enabled|bool
@ -178,5 +185,4 @@
register: nftables__register_systemd_service
when: (nft_enabled|bool and
nft_service_manage|bool)
notify: ['Restart nftables service']
notify: ['Restart nftables service']

4
vars/alpine.yml Normal file
View File

@ -0,0 +1,4 @@
---
# vars file for Alpine
nft_pkg_list:
- nftables

4
vars/archlinux.yml Normal file
View File

@ -0,0 +1,4 @@
---
# vars file for Archlinux-based distros
nft_pkg_list:
- nftables