This repository was archived by the owner on Apr 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Update README for TDD demo with molecule on backup_file role #16
Copy link
Copy link
Open
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed
Description
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.
---
- name: Backup file
ansible.builtin.copy:
src: "{{ backup_file_source_path }}"
dest: "{{ backup_file_destination_path }}"
mode: '0600'
remote_src: yes
backup_file/tasks/verify.yml
We will also need to make sure that backup_file_source_path is provided same as the backup_file_destination_path mentioned above.
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed