feat: add become: true, add vagrant tests, add systemd-resolved service check to avoid failure if service is not on host
All checks were successful
test / Linting (push) Successful in 28s
test / Molecule tests (default, ubuntu2004) (push) Successful in 47s
test / Molecule tests (default, debian12) (push) Successful in 1m15s
test / Molecule tests (default, debian11) (push) Successful in 1m24s
test / Molecule tests (default, ubuntu2204) (push) Successful in 52s
test / Molecule tests (with_custom_config, debian11) (push) Successful in 56s
test / Molecule tests (with_custom_config, ubuntu2004) (push) Successful in 31s
test / Molecule tests (with_custom_config, debian12) (push) Successful in 1m0s
test / Molecule tests (with_custom_config, ubuntu2204) (push) Successful in 46s

This commit is contained in:
Bertrand Lanson 2023-12-01 18:36:27 +01:00
parent d364c79650
commit 6218ed1fdd
13 changed files with 206 additions and 0 deletions

View File

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

View File

@ -0,0 +1,2 @@
---
dns_resolv_conf_path: '/tmp'

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,3 @@
---
# requirements file for molecule
roles: []

View File

@ -0,0 +1,47 @@
---
- 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: file /tmp/resolv.conf"
block:
- name: "Stat file /tmp/resolv.conf"
ansible.builtin.stat:
path: "/tmp/resolv.conf"
register: stat_tmp_resolv_conf
- name: "Slurp file /tmp/resolv.conf"
ansible.builtin.slurp:
src: "/tmp/resolv.conf"
register: slurp_tmp_resolv_conf
- name: "Verify file /tmp/resolv.conf"
ansible.builtin.assert:
that:
- stat_tmp_resolv_conf.stat.exists
- stat_tmp_resolv_conf.stat.isreg
- stat_tmp_resolv_conf.stat.pw_name == 'root'
- stat_tmp_resolv_conf.stat.gr_name == 'root'
- stat_tmp_resolv_conf.stat.mode == '0644'
- "'search local.lan' in (slurp_tmp_resolv_conf.content|b64decode)"
- "'nameserver 1.1.1.1' in (slurp_tmp_resolv_conf.content|b64decode)"
- "'nameserver 8.8.8.8' in (slurp_tmp_resolv_conf.content|b64decode)"

View File

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

View File

@ -0,0 +1,12 @@
---
dns_resolv_conf_disable_resolvectl: true
dns_resolv_conf_path: '/tmp'
dns_resolv_conf_nameservers:
- "10.1.20.53"
- "10.1.20.54"
dns_resolv_conf_domain: ""
dns_resolv_conf_search:
- "example.org"
- "az1.example.org"
dns_resolv_conf_sortlist: []
dns_resolv_conf_options: [edns0, rotate]

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,3 @@
---
# requirements file for molecule
roles: []

View File

@ -0,0 +1,48 @@
---
- 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: file /tmp/resolv.conf"
block:
- name: "Stat file /tmp/resolv.conf"
ansible.builtin.stat:
path: "/tmp/resolv.conf"
register: stat_tmp_resolv_conf
- name: "Slurp file /tmp/resolv.conf"
ansible.builtin.slurp:
src: "/tmp/resolv.conf"
register: slurp_tmp_resolv_conf
- name: "Verify file /tmp/resolv.conf"
ansible.builtin.assert:
that:
- stat_tmp_resolv_conf.stat.exists
- stat_tmp_resolv_conf.stat.isreg
- stat_tmp_resolv_conf.stat.pw_name == 'root'
- stat_tmp_resolv_conf.stat.gr_name == 'root'
- stat_tmp_resolv_conf.stat.mode == '0644'
- "'search example.org az1.example.org' in (slurp_tmp_resolv_conf.content|b64decode)"
- "'nameserver 10.1.20.53' in (slurp_tmp_resolv_conf.content|b64decode)"
- "'nameserver 10.1.20.54' in (slurp_tmp_resolv_conf.content|b64decode)"
- "'options edns0 rotate' in (slurp_tmp_resolv_conf.content|b64decode)"

View File

@ -7,3 +7,4 @@
owner: root owner: root
group: root group: root
mode: '0644' mode: '0644'
become: true

View File

@ -7,3 +7,4 @@
owner: root owner: root
group: root group: root
mode: '0644' mode: '0644'
become: true

View File

@ -1,7 +1,12 @@
--- ---
# task/systemd file for dns_resolver_conf # task/systemd file for dns_resolver_conf
- name: "Populate service facts"
ansible.builtin.service_facts:
- name: "Configure systemd-resolved" - name: "Configure systemd-resolved"
ansible.builtin.service: ansible.builtin.service:
name: systemd-resolved name: systemd-resolved
enabled: "{{ 'true' if not dns_resolv_conf_disable_resolvectl else 'false' }}" enabled: "{{ 'true' if not dns_resolv_conf_disable_resolvectl else 'false' }}"
state: "{{ 'started' if not dns_resolv_conf_disable_resolvectl else 'stopped' }}" state: "{{ 'started' if not dns_resolv_conf_disable_resolvectl else 'stopped' }}"
when: "'systemd-resolved.service' in ansible_facts.services"
become: true