diff --git a/.gitea/workflows/demo.yml b/.gitea/workflows/demo.yml index fee2cbd..afefc4c 100644 --- a/.gitea/workflows/demo.yml +++ b/.gitea/workflows/demo.yml @@ -15,8 +15,9 @@ jobs: uses: actions/setup-python@v5 with: python-version: '3.12' - - name: List files in the repository + - name: Set up molecule + run: pip install molecule + - name: Molecule test run: | - echo ${{ gitea.workspace }} - pip install molecule - which molecule + cd extensions + molecule test diff --git a/extensions/molecule/default/converge.yml b/extensions/molecule/default/converge.yml new file mode 100644 index 0000000..e600756 --- /dev/null +++ b/extensions/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/extensions/molecule/default/create.yml b/extensions/molecule/default/create.yml new file mode 100644 index 0000000..fcd6b92 --- /dev/null +++ b/extensions/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/extensions/molecule/default/destroy.yml b/extensions/molecule/default/destroy.yml new file mode 100644 index 0000000..59d6a8e --- /dev/null +++ b/extensions/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/extensions/molecule/default/molecule.yml b/extensions/molecule/default/molecule.yml new file mode 100644 index 0000000..afddece --- /dev/null +++ b/extensions/molecule/default/molecule.yml @@ -0,0 +1,8 @@ +--- +driver: + name: default +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