feat: add vagrant tests for later, add become: true to some tasks to not rely on ansible.cfg
Some checks failed
test / Linting (push) Failing after 10s
test / Molecule tests (default, debian11) (push) Has been skipped
test / Molecule tests (default, debian12) (push) Has been skipped
test / Molecule tests (default, ubuntu2004) (push) Has been skipped
test / Molecule tests (default, ubuntu2204) (push) Has been skipped
test / Molecule tests (with_custom_config, debian11) (push) Has been skipped
test / Molecule tests (with_custom_config, debian12) (push) Has been skipped
test / Molecule tests (with_custom_config, ubuntu2004) (push) Has been skipped
test / Molecule tests (with_custom_config, ubuntu2204) (push) Has been skipped

This commit is contained in:
Bertrand Lanson 2023-11-29 22:49:57 +01:00
parent 0999da1545
commit 3967974270
13 changed files with 241 additions and 0 deletions

View File

@ -3,6 +3,7 @@
- name: "Generate netplan configuration"
ansible.builtin.command: netplan generate
changed_when: false
become: true
listen: "netplan-generate"
- name: "Apply netplan configuration"
@ -10,3 +11,4 @@
listen: "netplan-apply"
changed_when: false
when: manage_netplan_apply
become: true

View File

@ -0,0 +1,7 @@
---
- name: Converge
hosts: all
tasks:
- name: "Include ednxzu.manage_netplan"
ansible.builtin.include_role:
name: "ednxzu.manage_netplan"

View File

@ -0,0 +1,35 @@
---
dependency:
name: galaxy
options:
requirements-file: ./requirements.yml
driver:
name: vagrant
provider:
name: libvirt
platforms:
- name: instance
box: generic/${MOLECULE_TEST_OS}
cpus: 4
memory: 4096
provisioner:
name: ansible
config_options:
defaults:
remote_tmp: /tmp/.ansible
verifier:
name: ansible
scenario:
name: default_vagrant
test_sequence:
- dependency
- cleanup
- destroy
- syntax
- create
- prepare
- converge
- idempotence
- verify
- cleanup
- destroy

View File

@ -0,0 +1,4 @@
---
# requirements file for molecule
roles:
- name: ednxzu.manage_apt_packages

View File

@ -0,0 +1,55 @@
---
- name: Verify
hosts: all
gather_facts: true
tasks:
- name: "Test: file /etc/hosts"
block:
- name: "Stat file /etc/hosts"
ansible.builtin.stat:
path: "/etc/hosts"
register: stat_etc_hosts
- name: "Verify file /etc/hosts"
vars:
etc_hosts_group:
ubuntu: "adm"
debian: "root"
ansible.builtin.assert:
that:
- stat_etc_hosts.stat.exists
- stat_etc_hosts.stat.isreg
- stat_etc_hosts.stat.pw_name == 'root'
- stat_etc_hosts.stat.gr_name == etc_hosts_group[(ansible_distribution|lower)]
- name: "Test: directory /etc/netplan"
block:
- name: "Stat directory /etc/netplan"
ansible.builtin.stat:
path: "/etc/netplan"
register: stat_etc_netplan
- name: "Stat file /etc/netplan/ansible-config.yaml"
ansible.builtin.stat:
path: "/etc/netplan/ansible-config.yaml"
register: stat_etc_netplan_ansible_config_yml
- name: "Slurp file /etc/netplan/ansible-config.yaml"
ansible.builtin.slurp:
src: "/etc/netplan/ansible-config.yaml"
register: slurp_etc_netplan_ansible_config_yml
- name: "Verify directory /etc/netplan"
ansible.builtin.assert:
that:
- stat_etc_netplan.stat.exists
- stat_etc_netplan.stat.isdir
- stat_etc_netplan.stat.pw_name == 'root'
- stat_etc_netplan.stat.gr_name == 'root'
- stat_etc_netplan.stat.mode == '0755'
- stat_etc_netplan_ansible_config_yml.stat.exists
- stat_etc_netplan_ansible_config_yml.stat.isreg
- stat_etc_netplan_ansible_config_yml.stat.pw_name == 'root'
- stat_etc_netplan_ansible_config_yml.stat.gr_name == 'root'
- stat_etc_netplan_ansible_config_yml.stat.mode == '0644'
- slurp_etc_netplan_ansible_config_yml.content != ''

View File

@ -0,0 +1,7 @@
---
- name: Converge
hosts: all
tasks:
- name: "Include ednxzu.manage_netplan"
ansible.builtin.include_role:
name: "ednxzu.manage_netplan"

View File

@ -0,0 +1,33 @@
---
manage_netplan_config_file: /tmp/ansible-config.yaml # this MUST be .yaml, .yml will not be picked up by netplan
manage_netplan_renderer: networkd # supported value is 'NetworkManager' or 'networkd'
manage_netplan_remove_existing: false
manage_netplan_search_domain: example.org
manage_netplan_install: true
manage_netplan_apply: false
manage_netplan_configuration:
network:
version: 2
ethernets:
eth1:
dhcp4: false
link-local: []
set-name: eth1
eth2:
dhcp4: true
mtu: 1500
link-local: []
set-name: eth2
vlans:
vlan20:
id: 20
link: eth1
mtu: 1500
dhcp4: false
link-local: []
vlan40:
id: 40
link: eth1
mtu: 1500
dhcp4: false
link-local: []

View File

@ -0,0 +1,35 @@
---
dependency:
name: galaxy
options:
requirements-file: ./requirements.yml
driver:
name: vagrant
provider:
name: libvirt
platforms:
- name: instance
box: generic/${MOLECULE_TEST_OS}
cpus: 4
memory: 4096
provisioner:
name: ansible
config_options:
defaults:
remote_tmp: /tmp/.ansible
verifier:
name: ansible
scenario:
name: with_custom_config_vagrant
test_sequence:
- dependency
- cleanup
- destroy
- syntax
- create
- prepare
- converge
- idempotence
- verify
- cleanup
- destroy

View File

@ -0,0 +1,4 @@
---
# requirements file for molecule
roles:
- name: ednxzu.manage_apt_packages

View File

@ -0,0 +1,55 @@
---
- name: Verify
hosts: all
gather_facts: true
tasks:
- name: "Test: file /etc/hosts"
block:
- name: "Stat file /etc/hosts"
ansible.builtin.stat:
path: "/etc/hosts"
register: stat_etc_hosts
- name: "Verify file /etc/hosts"
vars:
etc_hosts_group:
ubuntu: "adm"
debian: "root"
ansible.builtin.assert:
that:
- stat_etc_hosts.stat.exists
- stat_etc_hosts.stat.isreg
- stat_etc_hosts.stat.pw_name == 'root'
- stat_etc_hosts.stat.gr_name == etc_hosts_group[(ansible_distribution|lower)]
- name: "Test: directory /tmp"
block:
- name: "Stat directory /etc/netplan"
ansible.builtin.stat:
path: "/etc/netplan"
register: stat_etc_netplan
- name: "Stat file /tmp/ansible-config.yaml"
ansible.builtin.stat:
path: "/tmp/ansible-config.yaml"
register: stat_tmp_ansible_config_yml
- name: "Slurp file /tmp/ansible-config.yaml"
ansible.builtin.slurp:
src: "/tmp/ansible-config.yaml"
register: slurp_tmp_ansible_config_yml
- name: "Verify directory /tmp/netplan"
ansible.builtin.assert:
that:
- stat_etc_netplan.stat.exists
- stat_etc_netplan.stat.isdir
- stat_etc_netplan.stat.pw_name == 'root'
- stat_etc_netplan.stat.gr_name == 'root'
- stat_etc_netplan.stat.mode == '0755'
- stat_tmp_ansible_config_yml.stat.exists
- stat_tmp_ansible_config_yml.stat.isreg
- stat_tmp_ansible_config_yml.stat.pw_name == 'root'
- stat_tmp_ansible_config_yml.stat.gr_name == 'root'
- stat_tmp_ansible_config_yml.stat.mode == '0644'
- slurp_tmp_ansible_config_yml.content != ''

View File

@ -9,6 +9,7 @@
group: root
backup: true
when: manage_netplan_configuration != []
become: true
notify:
- "netplan-generate"
- "netplan-apply"

View File

@ -20,3 +20,4 @@
owner: "root"
group: "root"
mode: '0755'
become: true

View File

@ -5,6 +5,7 @@
paths: /etc/netplan
patterns: "*.yml,*.yaml"
register: _netplan_configs
become: true
- name: "Removing existing configurations"
ansible.builtin.file:
@ -13,3 +14,4 @@
loop: "{{ _netplan_configs['files'] }}"
when: item['path'] != manage_netplan_config_file
and manage_netplan_configuration != []
become: true