feat: add vagrant unit test for later
All checks were successful
test / Linting (push) Successful in 29s
test / Molecule tests (default, ubuntu2204) (push) Successful in 1m3s
test / Molecule tests (default, debian12) (push) Successful in 1m36s
test / Molecule tests (with_custom_packages, debian11) (push) Successful in 1m37s
test / Molecule tests (with_custom_packages, debian12) (push) Successful in 1m31s
test / Molecule tests (with_custom_packages, ubuntu2004) (push) Successful in 1m57s
test / Molecule tests (with_custom_packages, ubuntu2204) (push) Successful in 1m48s
test / Molecule tests (default, debian11) (push) Successful in 56s
test / Molecule tests (default, ubuntu2004) (push) Successful in 50s

This commit is contained in:
Bertrand Lanson 2023-11-29 19:13:41 +01:00
parent bdaec914f9
commit 2a3e54aa53
10 changed files with 196 additions and 0 deletions

View File

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

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,34 @@
---
- 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: package vim"
block:
- name: "Get packages facts"
ansible.builtin.package_facts:
manager: auto
- name: "Verify package vim"
ansible.builtin.assert:
that:
- "ansible_facts.packages['vim'][0]['name'] == 'vim'"

View File

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

View File

@ -0,0 +1,11 @@
---
manage_apt_packages_list:
- name: mariadb-server
version: latest
state: present
- name: apache2
version: latest
state: present
- name: consul
version: 1.13.1-1
state: present

View File

@ -0,0 +1,36 @@
---
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
#machine_virtual_size: 50
provisioner:
name: ansible
config_options:
defaults:
remote_tmp: /tmp/.ansible
verifier:
name: ansible
scenario:
name: with_custom_packages_vagrant
test_sequence:
- dependency
- cleanup
- destroy
- syntax
- create
- prepare
- converge
- idempotence
- verify
- cleanup
- destroy

View File

@ -0,0 +1,22 @@
---
- name: Prepare
hosts: all
tasks:
- name: "Include manage_repositories"
ansible.builtin.include_role:
name: "ednxzu.manage_repositories"
vars:
manage_repositories_enable_default_repo: true
manage_repositories_enable_custom_repo: true
manage_repositories_custom_repo:
- name: hashicorp
uri: "https://apt.releases.hashicorp.com"
comments: "hashicorp repository"
types:
- deb
suites:
- "{{ ansible_distribution_release }}"
components:
- main
options:
Signed-By: "https://apt.releases.hashicorp.com/gpg"

View File

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

View File

@ -0,0 +1,37 @@
---
- 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: packages mariadb-server, apache2, consul:1.13.1-1"
block:
- name: "Get packages facts"
ansible.builtin.package_facts:
manager: auto
- name: "Verify packages mariadb-server, apache2, consul:1.13.1-1"
ansible.builtin.assert:
that:
- "ansible_facts.packages['mariadb-server'][0]['name'] == 'mariadb-server'"
- "ansible_facts.packages['apache2'][0]['name'] == 'apache2'"
- "ansible_facts.packages['consul'][0]['name'] == 'consul'"
- "ansible_facts.packages['consul'][0]['version'] == '1.13.1-1'"