Files
Ansible-Bootstrap/tests/inputs/test_inputs.yml
T

91 lines
3.1 KiB
YAML

---
# Run: ansible-playbook tests/inputs/test_inputs.yml
- name: Strict input validator fixture tests
hosts: localhost
gather_facts: false
connection: local
vars_files:
- inputs_fixtures.yml
tasks:
- name: Run each input fixture
ansible.builtin.include_tasks: _assert_inputs.yml
loop: "{{ inputs_fixtures }}"
loop_control:
loop_var: inf
label: "{{ inf.name }}"
- name: Expand a spec pattern
validate_inputs:
specs:
- "{{ playbook_dir }}/fixture_*.yml"
vars:
fixture:
name: web01
servers: [10.0.0.1]
register: inputs_pattern_result
- name: Assert the pattern matched the fixture spec
ansible.builtin.assert:
that:
- inputs_pattern_result is succeeded
success_msg: "[inputs pattern] OK"
- name: Refuse a pattern that matches nothing
block:
- name: Run the validator with a pattern that matches no file
validate_inputs:
specs:
- "{{ playbook_dir }}/nothing_*.yml"
register: inputs_nomatch_result
rescue:
- name: Keep the no-match failure
ansible.builtin.set_fact:
inputs_nomatch_result: "{{ ansible_failed_result }}"
- name: Assert the empty pattern was refused
ansible.builtin.assert:
that:
- inputs_nomatch_result.msg is search('no spec file matches')
fail_msg: "[inputs no-match] got {{ inputs_nomatch_result.msg | default('') }}"
success_msg: "[inputs no-match] OK"
- name: Refuse a variable declared by two specs
block:
- name: Run the validator with the fixture spec twice
validate_inputs:
specs:
- "{{ playbook_dir }}/fixture_spec.yml"
- "{{ playbook_dir }}/fixture_spec.yml"
register: inputs_duplicate_result
rescue:
- name: Keep the duplicate-declaration failure
ansible.builtin.set_fact:
inputs_duplicate_result: "{{ ansible_failed_result }}"
- name: Assert the duplicate declaration was refused
ansible.builtin.assert:
that:
- inputs_duplicate_result.msg is search('fixture is declared by both')
fail_msg: "[inputs duplicate] got {{ inputs_duplicate_result.msg | default('') }}"
success_msg: "[inputs duplicate] OK"
- name: Validate a host var holding values that cannot be decrypted
block:
- name: Run the validator on the vaulted host var
validate_inputs:
specs:
- "{{ playbook_dir }}/fixture_spec.yml"
register: inputs_vault_result
rescue:
- name: Keep the failed vault result
ansible.builtin.set_fact:
inputs_vault_result: "{{ ansible_failed_result }}"
- name: Assert a vaulted string passes and a vaulted non-list is reported
ansible.builtin.assert:
that:
- >-
inputs_vault_result.errors | default([]) == ['fixture.servers: expected list, got str']
fail_msg: "[inputs vault] got {{ inputs_vault_result.errors | default([]) }}"
success_msg: "[inputs vault] OK"