# The hope is this one dictionary can define every aspect of the
# test so that the failure condition test can be imported with this
# one variable
test_details:
test_id: 001
test_name: "File does not exist"
test_fail_task: "Verify test exists"
test_fail_message: "FAIL: The file to be backed up does not exist"
# Want to define role variables as shown below
# variable names and values change depending on the role
# and so need to be very dynamic
test_vars:
target_file: '/file/location'
target_dest: 'file/location2'
test_role: 'my_role'
# BEGIN REUSABLE BIT
# All expected failing tests can reuse the same block below
# if the test_vars are passed to the role as shown below
- name: testing block
block:
- name: include role
ansible.builtin.include_role:
name: "{{ test_vars.test_role }}"
# Passing in the dictionary doesn't work like this
# need to strip out the "test_vars" level and just nest
# the level below under "vars:"
vars: "{{ test_vars }}" # << Want to add variables here
rescue:
<snip>
always:
<snip>
# --------------- So that it acts like this below
<snip>
- name: include role
ansible.builtin.include_role:
name: "{{ test_vars.test_role }}"
vars:
target_file: '/file/location'
target_dest: 'file/location2'
test_role: 'my_role'
<snip>
lots more code below