Merge remote-tracking branch 'github/add_molecule'
This commit is contained in:
commit
bac335be11
|
@ -0,0 +1,4 @@
|
||||||
|
skip_list:
|
||||||
|
- command-instead-of-module
|
||||||
|
- no-changed-when
|
||||||
|
- role-name
|
|
@ -1,20 +1,23 @@
|
||||||
---
|
---
|
||||||
name: Molecule
|
name: ipr-cnrs.nftables.molecule
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [master]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [main]
|
branches: [master]
|
||||||
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Ansible Molecule
|
- name: checkout
|
||||||
uses: MonolithProjects/action-molecule@v1.4.3
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
path: "${{ github.repository }}"
|
||||||
|
|
||||||
|
- name: molecule
|
||||||
|
uses: robertdebock/molecule-action@2.6.17
|
|
@ -4,6 +4,8 @@ dependencies: []
|
||||||
|
|
||||||
galaxy_info:
|
galaxy_info:
|
||||||
author: "Jérémy Gardais"
|
author: "Jérémy Gardais"
|
||||||
|
namespace: ipr-cnrs
|
||||||
|
role_name: nftables
|
||||||
description: "Manage Nftables rules and packages"
|
description: "Manage Nftables rules and packages"
|
||||||
license: WTFPL
|
license: WTFPL
|
||||||
company: IPR
|
company: IPR
|
||||||
|
|
|
@ -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"]
|
|
@ -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
|
|
@ -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
|
|
@ -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"'
|
|
@ -1,7 +1,9 @@
|
||||||
---
|
---
|
||||||
- name: Converge
|
- name: Converge
|
||||||
hosts: all
|
hosts: all
|
||||||
|
gather_facts: yes
|
||||||
roles:
|
roles:
|
||||||
- role: ipr-cnrs.nftables
|
- role: ipr-cnrs.nftables
|
||||||
|
nft_debug: true
|
||||||
|
# can't remove iptables on an instance with docker
|
||||||
|
nft_old_pkg_manage: false
|
|
@ -1,11 +1,54 @@
|
||||||
---
|
---
|
||||||
dependency:
|
dependency:
|
||||||
name: galaxy
|
name: galaxy
|
||||||
|
lint: |
|
||||||
|
set -e
|
||||||
|
yamllint .
|
||||||
|
ansible-lint
|
||||||
driver:
|
driver:
|
||||||
name: docker
|
name: docker
|
||||||
platforms:
|
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:
|
provisioner:
|
||||||
name: ansible
|
name: ansible
|
||||||
verifier:
|
verifier:
|
||||||
|
|
|
@ -5,6 +5,68 @@
|
||||||
hosts: all
|
hosts: all
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
tasks:
|
tasks:
|
||||||
- name: Example assertion
|
|
||||||
|
- name: check for nftables.d
|
||||||
|
stat:
|
||||||
|
path: /etc/nftables.d
|
||||||
|
register: p
|
||||||
|
|
||||||
|
- name: check nftables.d
|
||||||
assert:
|
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"'
|
||||||
|
|
|
@ -13,7 +13,8 @@
|
||||||
loop_control:
|
loop_control:
|
||||||
loop_var: groupname
|
loop_var: groupname
|
||||||
|
|
||||||
- debug: var=nftables_group_rules
|
- name: Debug nftables_group_rules
|
||||||
|
debug: var=nftables_group_rules
|
||||||
when: nft_debug
|
when: nft_debug
|
||||||
|
|
||||||
- name: Import nftables-variables if nft_merged_groups is set
|
- name: Import nftables-variables if nft_merged_groups is set
|
||||||
|
@ -36,7 +37,12 @@
|
||||||
loop_control:
|
loop_control:
|
||||||
loop_var: varfile
|
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
|
when: nft_debug
|
||||||
|
|
||||||
- name: Load specific OS vars for nftables
|
- name: Load specific OS vars for nftables
|
||||||
|
@ -53,6 +59,7 @@
|
||||||
package:
|
package:
|
||||||
name: '{{ nft_pkg_list | list }}'
|
name: '{{ nft_pkg_list | list }}'
|
||||||
state: '{{ nft_pkg_state }}'
|
state: '{{ nft_pkg_state }}'
|
||||||
|
update_cache: true
|
||||||
register: pkg_install_result
|
register: pkg_install_result
|
||||||
until: pkg_install_result is success
|
until: pkg_install_result is success
|
||||||
when: nft_enabled|bool
|
when: nft_enabled|bool
|
||||||
|
@ -179,4 +186,3 @@
|
||||||
when: (nft_enabled|bool and
|
when: (nft_enabled|bool and
|
||||||
nft_service_manage|bool)
|
nft_service_manage|bool)
|
||||||
notify: ['Restart nftables service']
|
notify: ['Restart nftables service']
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
# vars file for Alpine
|
||||||
|
nft_pkg_list:
|
||||||
|
- nftables
|
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
# vars file for Archlinux-based distros
|
||||||
|
nft_pkg_list:
|
||||||
|
- nftables
|
Loading…
Reference in New Issue