From 9559d7debababe94a20f8c5e5e7f109623afe124 Mon Sep 17 00:00:00 2001 From: Boris Glimcher Date: Thu, 8 Feb 2024 02:32:08 +0200 Subject: [PATCH] ci: add molecule Signed-off-by: Boris Glimcher --- .../molecule/default/converge.yml | 8 +++++ .../bmc_fw_update/molecule/default/create.yml | 35 +++++++++++++++++++ .../molecule/default/destroy.yml | 24 +++++++++++++ .../molecule/default/molecule.yml | 6 ++++ 4 files changed, 73 insertions(+) create mode 100644 roles/bmc_fw_update/molecule/default/converge.yml create mode 100644 roles/bmc_fw_update/molecule/default/create.yml create mode 100644 roles/bmc_fw_update/molecule/default/destroy.yml create mode 100644 roles/bmc_fw_update/molecule/default/molecule.yml diff --git a/roles/bmc_fw_update/molecule/default/converge.yml b/roles/bmc_fw_update/molecule/default/converge.yml new file mode 100644 index 0000000..e600756 --- /dev/null +++ b/roles/bmc_fw_update/molecule/default/converge.yml @@ -0,0 +1,8 @@ +--- +- name: Converge + hosts: all + gather_facts: false + tasks: + - name: Replace this task with one that validates your content + ansible.builtin.debug: + msg: "This is the effective test" diff --git a/roles/bmc_fw_update/molecule/default/create.yml b/roles/bmc_fw_update/molecule/default/create.yml new file mode 100644 index 0000000..fcd6b92 --- /dev/null +++ b/roles/bmc_fw_update/molecule/default/create.yml @@ -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" diff --git a/roles/bmc_fw_update/molecule/default/destroy.yml b/roles/bmc_fw_update/molecule/default/destroy.yml new file mode 100644 index 0000000..59d6a8e --- /dev/null +++ b/roles/bmc_fw_update/molecule/default/destroy.yml @@ -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 diff --git a/roles/bmc_fw_update/molecule/default/molecule.yml b/roles/bmc_fw_update/molecule/default/molecule.yml new file mode 100644 index 0000000..b524ee7 --- /dev/null +++ b/roles/bmc_fw_update/molecule/default/molecule.yml @@ -0,0 +1,6 @@ +--- +platforms: + - name: instance + # you might want to add your own variables here based on what provisioning + # you are doing like: + # image: quay.io/centos/centos:stream8