Skip to content
This repository was archived by the owner on Apr 9, 2024. It is now read-only.

Update README for TDD demo with molecule on backup_file role #16

@jeffcpullen

Description

@jeffcpullen

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

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or requestgood first issueGood for newcomershelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions