summaryrefslogtreecommitdiff
path: root/tests/render/render.yml
blob: 1e0bd21323213c9512e266b5e46000d1821baba0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
---
- name: Render a role offline and compare with its golden commands
  hosts: all
  gather_facts: false
  vars:
    _expected_file: "{{ case_dir }}/expected/{{ inventory_hostname }}.txt"
  tasks:
    - name: Render the role(s)
      ansible.builtin.include_role:
        name: "vyos.blueprints.{{ item }}"
      vars:
        vyos_blueprints_render_only: true
      loop: "{{ render_roles.split(',') if render_roles | default('') | length > 0 else [role] }}"

    - name: Normalise rendered commands
      ansible.builtin.set_fact:
        _actual: "{{ vyos_blueprints_rendered | default([]) | map('trim') | sort }}"

    - name: Write golden file
      ansible.builtin.copy:
        content: "{{ _actual | join('\n') }}\n"
        dest: "{{ _expected_file }}"
        mode: "0644"
      delegate_to: localhost
      when: update_golden | bool

    - name: Compare with golden file
      ansible.builtin.assert:
        that: _actual == _expected
        fail_msg: |
          Rendered commands differ from {{ _expected_file }}
          missing: {{ _expected | difference(_actual) }}
          unexpected: {{ _actual | difference(_expected) }}
        success_msg: "{{ _actual | length }} commands match"
      vars:
        _expected: "{{ lookup('ansible.builtin.file', _expected_file).splitlines() | map('trim') | select | sort }}"
      when: not (update_golden | bool)