diff --git a/collections/ansible_collections/theliberatededge/test_linux_containers/extensions/molecule/default/converge.yml b/collections/ansible_collections/theliberatededge/test_linux_containers/extensions/molecule/default/converge.yml new file mode 100644 index 0000000..c7f4c47 --- /dev/null +++ b/collections/ansible_collections/theliberatededge/test_linux_containers/extensions/molecule/default/converge.yml @@ -0,0 +1,7 @@ +--- +- name: Converge + hosts: all + gather_facts: false + +- name: imports and executes the playbook under test + ansible.builtin.import_playbook: ../../../launch_linux_container.yml diff --git a/collections/ansible_collections/theliberatededge/test_linux_containers/extensions/molecule/default/create.yml b/collections/ansible_collections/theliberatededge/test_linux_containers/extensions/molecule/default/create.yml new file mode 100644 index 0000000..371214e --- /dev/null +++ b/collections/ansible_collections/theliberatededge/test_linux_containers/extensions/molecule/default/create.yml @@ -0,0 +1,36 @@ +--- +- 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/collections/ansible_collections/theliberatededge/test_linux_containers/extensions/molecule/default/destroy.yml b/collections/ansible_collections/theliberatededge/test_linux_containers/extensions/molecule/default/destroy.yml new file mode 100644 index 0000000..5ba2d23 --- /dev/null +++ b/collections/ansible_collections/theliberatededge/test_linux_containers/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/collections/ansible_collections/theliberatededge/test_linux_containers/extensions/molecule/default/molecule.yml b/collections/ansible_collections/theliberatededge/test_linux_containers/extensions/molecule/default/molecule.yml new file mode 100644 index 0000000..f291e2b --- /dev/null +++ b/collections/ansible_collections/theliberatededge/test_linux_containers/extensions/molecule/default/molecule.yml @@ -0,0 +1,7 @@ +--- +dependency: + name: galaxy +platforms: + - name: instance +verifier: + name: ansible diff --git a/collections/ansible_collections/theliberatededge/test_linux_containers/extensions/molecule/default/verify.yml b/collections/ansible_collections/theliberatededge/test_linux_containers/extensions/molecule/default/verify.yml new file mode 100644 index 0000000..f91205f --- /dev/null +++ b/collections/ansible_collections/theliberatededge/test_linux_containers/extensions/molecule/default/verify.yml @@ -0,0 +1,12 @@ +--- +- name: Verify + hosts: localhost + gather_facts: false + tasks: + - name: stat file + ansible.builtin.stat: + path: ~/tst.log + register: stat_result + - name: verify file exists + assert: + that: stat_result.stat.exists diff --git a/collections/ansible_collections/theliberatededge/test_linux_containers/roles/linux_container/tasks/main.yml b/collections/ansible_collections/theliberatededge/test_linux_containers/roles/linux_container/tasks/main.yml index 213dad7..8490985 100644 --- a/collections/ansible_collections/theliberatededge/test_linux_containers/roles/linux_container/tasks/main.yml +++ b/collections/ansible_collections/theliberatededge/test_linux_containers/roles/linux_container/tasks/main.yml @@ -1,4 +1,6 @@ --- - name: Task is running from within the role - ansible.builtin.debug: - msg: "This is a task from the linux_container role." + ansible.builtin.file: + path: ~/tst.log + state: touch + changed_when: false