moving to molecule
This commit is contained in:
10
molecule/fedora/converge.yml
Normal file
10
molecule/fedora/converge.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
# Purpose: bring the instance to the desired state by running the role under test.
|
||||
# Molecule calls this playbook with `molecule converge`.
|
||||
- name: Converge
|
||||
hosts: all
|
||||
gather_facts: true # Disable if your role does not rely on facts
|
||||
tasks:
|
||||
- name: Apply role under test
|
||||
ansible.builtin.include_role:
|
||||
name: yournamespace.yourcollection.yourrole
|
||||
35
molecule/fedora/create.yml
Normal file
35
molecule/fedora/create.yml
Normal file
@@ -0,0 +1,35 @@
|
||||
---
|
||||
- name: Create
|
||||
hosts: localhost
|
||||
connection: local
|
||||
gather_facts: false
|
||||
# no_log: "{{ molecule_no_log }}"
|
||||
tasks:
|
||||
# TODO: Developer must implement and populate 'server' variable
|
||||
|
||||
- name: Create instance config
|
||||
when: server.changed | default(false) | bool # noqa no-handler
|
||||
block:
|
||||
- name: Populate instance config dict # noqa jinja
|
||||
ansible.builtin.set_fact:
|
||||
instance_conf_dict: {}
|
||||
# instance': "{{ }}",
|
||||
# address': "{{ }}",
|
||||
# user': "{{ }}",
|
||||
# port': "{{ }}",
|
||||
# 'identity_file': "{{ }}", }
|
||||
with_items: "{{ server.results }}"
|
||||
register: instance_config_dict
|
||||
|
||||
- name: Convert instance config dict to a list
|
||||
ansible.builtin.set_fact:
|
||||
instance_conf: "{{ instance_config_dict.results | map(attribute='ansible_facts.instance_conf_dict') | list }}"
|
||||
|
||||
- name: Dump instance config
|
||||
ansible.builtin.copy:
|
||||
content: |
|
||||
# Molecule managed
|
||||
|
||||
{{ instance_conf | to_json | from_json | to_yaml }}
|
||||
dest: "{{ molecule_instance_config }}"
|
||||
mode: "0600"
|
||||
24
molecule/fedora/destroy.yml
Normal file
24
molecule/fedora/destroy.yml
Normal file
@@ -0,0 +1,24 @@
|
||||
---
|
||||
- name: Destroy
|
||||
hosts: localhost
|
||||
connection: local
|
||||
gather_facts: false
|
||||
# no_log: "{{ molecule_no_log }}"
|
||||
tasks:
|
||||
# Developer must implement.
|
||||
|
||||
# Mandatory configuration for Molecule to function.
|
||||
|
||||
- name: Populate instance config
|
||||
ansible.builtin.set_fact:
|
||||
instance_conf: {}
|
||||
|
||||
- name: Dump instance config
|
||||
ansible.builtin.copy:
|
||||
content: |
|
||||
# Molecule managed
|
||||
|
||||
{{ instance_conf | to_json | from_json | to_yaml }}
|
||||
dest: "{{ molecule_instance_config }}"
|
||||
mode: "0600"
|
||||
when: server.changed | default(false) | bool # noqa no-handler
|
||||
10
molecule/fedora/inventory.yml
Normal file
10
molecule/fedora/inventory.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
all:
|
||||
children:
|
||||
builders:
|
||||
hosts:
|
||||
fedora-test:
|
||||
ansible_host: fedora-test
|
||||
container_image: registry.fedoraproject.org/fedora:latest
|
||||
container_command: /sbin/init
|
||||
container_privileged: true
|
||||
47
molecule/fedora/molecule.yml
Normal file
47
molecule/fedora/molecule.yml
Normal file
@@ -0,0 +1,47 @@
|
||||
---
|
||||
# Dependency management (download roles/collections)
|
||||
dependency:
|
||||
name: galaxy
|
||||
options:
|
||||
requirements-file: ../requirements.yml
|
||||
|
||||
|
||||
ansible:
|
||||
cfg:
|
||||
defaults:
|
||||
host_key_checking: false
|
||||
verbosity: 1
|
||||
|
||||
executor:
|
||||
backend: ansible-playbook
|
||||
args:
|
||||
ansible_playbook:
|
||||
- --diff
|
||||
- --force-handlers
|
||||
- --inventory=/path/to/inventory.yml
|
||||
ansible_navigator:
|
||||
- --mode stdout
|
||||
- --pull-policy missing
|
||||
- --execution-environment-image ghcr.io/ansible/community-ansible-dev-tools:latest
|
||||
|
||||
playbooks:
|
||||
create: create.yml
|
||||
converge: converge.yml
|
||||
destroy: destroy.yml
|
||||
cleanup: cleanup.yml
|
||||
prepare: prepare.yml
|
||||
side_effect: side_effect.yml
|
||||
verify: verify.yml
|
||||
|
||||
scenario:
|
||||
name: fedora
|
||||
test_sequence:
|
||||
- dependency
|
||||
- syntax
|
||||
- create
|
||||
- prepare
|
||||
- converge
|
||||
- idempotence
|
||||
- verify
|
||||
- cleanup
|
||||
- destroy
|
||||
10
molecule/fedora/verify.yml
Normal file
10
molecule/fedora/verify.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
# Purpose: assert that the instance really ended up in the expected state.
|
||||
# Molecule calls this playbook with `molecule verify`.
|
||||
- name: Verify
|
||||
hosts: instance
|
||||
gather_facts: false # Quicker, if you do not need facts
|
||||
tasks:
|
||||
- name: Assert something
|
||||
ansible.builtin.assert:
|
||||
that: true
|
||||
4
molecule/requirements.yml
Normal file
4
molecule/requirements.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
collections:
|
||||
- name: containers.podman
|
||||
version: ">=1.10.0"
|
||||
Reference in New Issue
Block a user