The backup_file role is setup nicely to demonstrate a simple test driven development example by adding verification to the role.
This would involve adding code to the molecule/default/verify.yml file like this.
---
- name: Verify
hosts: all
connection: community.okd.oc
gather_facts: false
tasks:
- name: Check if backup file was created
ansible.builtin.stat:
path: "{{ backup_file_destination_path }}"
register: __backup_file_verify_file
- name: Debug backup file variable
ansible.builtin.debug:
var: __backup_file_verify_file
- name: Example assertion
ansible.builtin.assert:
that:
- __backup_file_verify_file.stat.exists
This assumes that the backup_file_destination_path is defined. The playbook will fail if this isn't defined (which is another verification that could be added). Or it can be defined in the molecule.yml file under the group_vars.
Running molecule test or molecule verify if the molecule create && molecule converge has already been run.
To have this test pass the role could be updated to include tasks like this.
The backup_file role is setup nicely to demonstrate a simple test driven development example by adding verification to the role.
This would involve adding code to the molecule/default/verify.yml file like this.
This assumes that the backup_file_destination_path is defined. The playbook will fail if this isn't defined (which is another verification that could be added). Or it can be defined in the molecule.yml file under the group_vars.
Running
molecule test
ormolecule verify
if themolecule create && molecule converge
has already been run.To have this test pass the role could be updated to include tasks like this.
We will also need to make sure that backup_file_source_path is provided same as the backup_file_destination_path mentioned above.