diff --git a/docs/ansible.utils.consolidate_filter.rst b/docs/ansible.utils.consolidate_filter.rst index 3b97abb..01622da 100644 --- a/docs/ansible.utils.consolidate_filter.rst +++ b/docs/ansible.utils.consolidate_filter.rst @@ -185,9 +185,10 @@ Examples .. code-block:: yaml # Consolidated facts example - # ------------ + # -------------------------- ##facts.yml + interfaces: - name: GigabitEthernet0/0 enabled: true @@ -270,25 +271,25 @@ Examples - name: Loopback999 ##Playbook - vars_files: - - "facts.yml" - tasks: - - name: Build the facts collection - set_fact: - data_source: - - data: "{{ interfaces }}" - match_key: name - prefix: interfaces - - data: "{{ l2_interfaces }}" - match_key: name - prefix: l2_interfaces - - data: "{{ l3_interfaces }}" - match_key: name - prefix: l3_interfaces + vars_files: + - "facts.yml" + tasks: + - name: Build the facts collection + set_fact: + data_source: + - data: "{{ interfaces }}" + match_key: name + prefix: interfaces + - data: "{{ l2_interfaces }}" + match_key: name + prefix: l2_interfaces + - data: "{{ l3_interfaces }}" + match_key: name + prefix: l3_interfaces - - name: Combine all the facts based on match_keys - set_fact: - combined: "{{ data_source|ansible.utils.consolidate(fail_missing_match_value=False) }}" + - name: Combine all the facts based on match_keys + set_fact: + combined: "{{ data_source|ansible.utils.consolidate(fail_missing_match_value=False) }}" ##Output # ok: [localhost] => { @@ -431,7 +432,7 @@ Examples # } # Read vars_file 'facts.yml' - # TASK [Combine all the facts based on match_keys] **************************************************************************************************************** + # TASK [Combine all the facts based on match_keys] # ok: [localhost] => { # "ansible_facts": { # "combined": { @@ -653,171 +654,172 @@ Examples - name: Loopback999 ##Playbook - vars_files: - - "facts.yml" - tasks: - - name: Build the facts collection - set_fact: - data_source: - - data: "{{ interfaces }}" - match_key: name - prefix: interfaces - - data: "{{ l2_interfaces }}" - match_key: name - prefix: l2_interfaces - - data: "{{ l3_interfaces }}" - match_key: name - prefix: l3_interfaces + vars_files: + - "facts.yml" + tasks: + - name: Build the facts collection + set_fact: + data_source: + - data: "{{ interfaces }}" + match_key: name + prefix: interfaces + - data: "{{ l2_interfaces }}" + match_key: name + prefix: l2_interfaces + - data: "{{ l3_interfaces }}" + match_key: name + prefix: l3_interfaces - - name: Combine all the facts based on match_keys - set_fact: - combined: "{{ data_source|ansible.utils.consolidate(fail_missing_match_value=True) }}" + - name: Combine all the facts based on match_keys + set_fact: + combined: "{{ data_source|ansible.utils.consolidate(fail_missing_match_value=True) }}" ##Output - ok: [localhost] => { - "ansible_facts": { - "data_source": [ - { - "data": [ - { - "duplex": "auto", - "enabled": true, - "name": "GigabitEthernet0/0", - "note": [ - "Connected green wire" - ], - "speed": "auto" - }, - { - "description": "Configured by Ansible - Interface 1", - "duplex": "auto", - "enabled": true, - "mtu": 1500, - "name": "GigabitEthernet0/1", - "note": [ - "Connected blue wire", - "Configured by Paul" - ], - "speed": "auto", - "vifs": [ - { - "comment": "Needs reconfiguration", - "description": "Eth1 - VIF 100", - "enabled": true, - "mtu": 400, - "vlan_id": 100 - }, - { - "description": "Eth1 - VIF 101", - "enabled": true, - "vlan_id": 101 - } - ] - }, - { - "description": "Configured by Ansible - Interface 2 (ADMIN DOWN)", - "enabled": false, - "mtu": 600, - "name": "GigabitEthernet0/2" - } - ], - "match_key": "name", - "prefix": "interfaces" - }, - { - "data": [ - { - "name": "GigabitEthernet0/0" - }, - { - "mode": "access", - "name": "GigabitEthernet0/1", - "trunk": { - "allowed_vlans": [ - "11", - "12", - "59", - "67", - "75", - "77", - "81", - "100", - "400-408", - "411-413", - "415", - "418", - "982", - "986", - "988", - "993" - ] - } - }, - { - "mode": "trunk", - "name": "GigabitEthernet0/2", - "trunk": { - "allowed_vlans": [ - "11", - "12", - "59", - "67", - "75", - "77", - "81", - "100", - "400-408", - "411-413", - "415", - "418", - "982", - "986", - "988", - "993" - ], - "encapsulation": "dot1q" - } - } - ], - "match_key": "name", - "prefix": "l2_interfaces" - }, - { - "data": [ - { - "ipv4": [ - { - "address": "192.168.0.2/24" - } - ], - "name": "GigabitEthernet0/0" - }, - { - "name": "GigabitEthernet0/1" - }, - { - "name": "GigabitEthernet0/2" - }, - { - "name": "Loopback888" - }, - { - "name": "Loopback999" - } - ], - "match_key": "name", - "prefix": "l3_interfaces" - } - ] - }, - "changed": false - } - Read vars_file 'facts.yml' + # ok: [localhost] => { + # "ansible_facts": { + # "data_source": [ + # { + # "data": [ + # { + # "duplex": "auto", + # "enabled": true, + # "name": "GigabitEthernet0/0", + # "note": [ + # "Connected green wire" + # ], + # "speed": "auto" + # }, + # { + # "description": "Configured by Ansible - Interface 1", + # "duplex": "auto", + # "enabled": true, + # "mtu": 1500, + # "name": "GigabitEthernet0/1", + # "note": [ + # "Connected blue wire", + # "Configured by Paul" + # ], + # "speed": "auto", + # "vifs": [ + # { + # "comment": "Needs reconfiguration", + # "description": "Eth1 - VIF 100", + # "enabled": true, + # "mtu": 400, + # "vlan_id": 100 + # }, + # { + # "description": "Eth1 - VIF 101", + # "enabled": true, + # "vlan_id": 101 + # } + # ] + # }, + # { + # "description": "Configured by Ansible - Interface 2 (ADMIN DOWN)", + # "enabled": false, + # "mtu": 600, + # "name": "GigabitEthernet0/2" + # } + # ], + # "match_key": "name", + # "prefix": "interfaces" + # }, + # { + # "data": [ + # { + # "name": "GigabitEthernet0/0" + # }, + # { + # "mode": "access", + # "name": "GigabitEthernet0/1", + # "trunk": { + # "allowed_vlans": [ + # "11", + # "12", + # "59", + # "67", + # "75", + # "77", + # "81", + # "100", + # "400-408", + # "411-413", + # "415", + # "418", + # "982", + # "986", + # "988", + # "993" + # ] + # } + # }, + # { + # "mode": "trunk", + # "name": "GigabitEthernet0/2", + # "trunk": { + # "allowed_vlans": [ + # "11", + # "12", + # "59", + # "67", + # "75", + # "77", + # "81", + # "100", + # "400-408", + # "411-413", + # "415", + # "418", + # "982", + # "986", + # "988", + # "993" + # ], + # "encapsulation": "dot1q" + # } + # } + # ], + # "match_key": "name", + # "prefix": "l2_interfaces" + # }, + # { + # "data": [ + # { + # "ipv4": [ + # { + # "address": "192.168.0.2/24" + # } + # ], + # "name": "GigabitEthernet0/0" + # }, + # { + # "name": "GigabitEthernet0/1" + # }, + # { + # "name": "GigabitEthernet0/2" + # }, + # { + # "name": "Loopback888" + # }, + # { + # "name": "Loopback999" + # } + # ], + # "match_key": "name", + # "prefix": "l3_interfaces" + # } + # ] + # }, + # "changed": false + # } + # Read vars_file 'facts.yml' - TASK [Combine all the facts based on match_keys] **************************************************************************************************************** - fatal: [localhost]: FAILED! => { - "msg": "Error when using plugin 'consolidate': 'fail_missing_match_value' reported Missing match value Loopback999, Loopback888 in data source 0, Missing match value Loopback999, Loopback888 in data source 1" - } + # TASK [Combine all the facts based on match_keys] + # fatal: [localhost]: FAILED! => { + # "msg": "Error when using plugin 'consolidate': 'fail_missing_match_value' reported Missing match value Loopback999, + # Loopback888 in data source 0, Missing match value Loopback999, Loopback888 in data source 1" + # } # Failing on missing match keys # ----------------------------- @@ -905,25 +907,25 @@ Examples - inft_name: Loopback999 ##Playbook - vars_files: - - "facts.yml" - tasks: - - name: Build the facts collection - set_fact: - data_source: - - data: "{{ interfaces }}" - match_key: name - prefix: interfaces - - data: "{{ l2_interfaces }}" - match_key: name - prefix: l2_interfaces - - data: "{{ l3_interfaces }}" - match_key: name - prefix: l3_interfaces + vars_files: + - "facts.yml" + tasks: + - name: Build the facts collection + set_fact: + data_source: + - data: "{{ interfaces }}" + match_key: name + prefix: interfaces + - data: "{{ l2_interfaces }}" + match_key: name + prefix: l2_interfaces + - data: "{{ l3_interfaces }}" + match_key: name + prefix: l3_interfaces - - name: Combine all the facts based on match_keys - set_fact: - combined: "{{ data_source|ansible.utils.consolidate(fail_missing_match_key=True) }}" + - name: Combine all the facts based on match_keys + set_fact: + combined: "{{ data_source|ansible.utils.consolidate(fail_missing_match_key=True) }}" ##Output # ok: [localhost] => { @@ -1066,9 +1068,13 @@ Examples # } # Read vars_file 'facts.yml' - # TASK [Combine all the facts based on match_keys] **************************************************************************************************************** + # TASK [Combine all the facts based on match_keys] # fatal: [localhost]: FAILED! => { - # "msg": "Error when using plugin 'consolidate': 'fail_missing_match_key' reported Missing match key 'name' in data source 2 in list entry 0, Missing match key 'name' in data source 2 in list entry 1, Missing match key 'name' in data source 2 in list entry 2, Missing match key 'name' in data source 2 in list entry 3, Missing match key 'name' in data source 2 in list entry 4" + # "msg": "Error when using plugin 'consolidate': 'fail_missing_match_key' reported Missing match + # key 'name' in data source 2 in list entry 0, Missing match key 'name' in data + # source 2 in list entry 1, Missing match key 'name' in data source 2 in list + # entry 2, Missing match key 'name' in data source 2 in list entry 3, Missing + # match key 'name' in data source 2 in list entry 4" # } # Failing on duplicate values in facts @@ -1158,174 +1164,174 @@ Examples - name: Loopback999 ##Playbook - vars_files: - - "facts.yml" - tasks: - - name: Build the facts collection - set_fact: - data_source: - - data: "{{ interfaces }}" - match_key: name - prefix: interfaces - - data: "{{ l2_interfaces }}" - match_key: name - prefix: l2_interfaces - - data: "{{ l3_interfaces }}" - match_key: name - prefix: l3_interfaces + vars_files: + - "facts.yml" + tasks: + - name: Build the facts collection + set_fact: + data_source: + - data: "{{ interfaces }}" + match_key: name + prefix: interfaces + - data: "{{ l2_interfaces }}" + match_key: name + prefix: l2_interfaces + - data: "{{ l3_interfaces }}" + match_key: name + prefix: l3_interfaces - - name: Combine all the facts based on match_keys - set_fact: - combined: "{{ data_source|ansible.utils.consolidate(fail_duplicate=True) }}" + - name: Combine all the facts based on match_keys + set_fact: + combined: "{{ data_source|ansible.utils.consolidate(fail_duplicate=True) }}" ##Output - ok: [localhost] => { - "ansible_facts": { - "data_source": [ - { - "data": [ - { - "duplex": "auto", - "enabled": true, - "name": "GigabitEthernet0/0", - "note": [ - "Connected green wire" - ], - "speed": "auto" - }, - { - "description": "Configured by Ansible - Interface 1", - "duplex": "auto", - "enabled": true, - "mtu": 1500, - "name": "GigabitEthernet0/1", - "note": [ - "Connected blue wire", - "Configured by Paul" - ], - "speed": "auto", - "vifs": [ - { - "comment": "Needs reconfiguration", - "description": "Eth1 - VIF 100", - "enabled": true, - "mtu": 400, - "vlan_id": 100 - }, - { - "description": "Eth1 - VIF 101", - "enabled": true, - "vlan_id": 101 - } - ] - }, - { - "description": "Configured by Ansible - Interface 2 (ADMIN DOWN)", - "enabled": false, - "mtu": 600, - "name": "GigabitEthernet0/2" - } - ], - "match_key": "name", - "prefix": "interfaces" - }, - { - "data": [ - { - "name": "GigabitEthernet0/0" - }, - { - "name": "GigabitEthernet0/0" - }, - { - "mode": "access", - "name": "GigabitEthernet0/1", - "trunk": { - "allowed_vlans": [ - "11", - "12", - "59", - "67", - "75", - "77", - "81", - "100", - "400-408", - "411-413", - "415", - "418", - "982", - "986", - "988", - "993" - ] - } - }, - { - "mode": "trunk", - "name": "GigabitEthernet0/2", - "trunk": { - "allowed_vlans": [ - "11", - "12", - "59", - "67", - "75", - "77", - "81", - "100", - "400-408", - "411-413", - "415", - "418", - "982", - "986", - "988", - "993" - ], - "encapsulation": "dot1q" - } - } - ], - "match_key": "name", - "prefix": "l2_interfaces" - }, - { - "data": [ - { - "ipv4": [ - { - "address": "192.168.0.2/24" - } - ], - "name": "GigabitEthernet0/0" - }, - { - "name": "GigabitEthernet0/1" - }, - { - "name": "GigabitEthernet0/2" - }, - { - "name": "Loopback888" - }, - { - "name": "Loopback999" - } - ], - "match_key": "name", - "prefix": "l3_interfaces" - } - ] - }, - "changed": false - } - Read vars_file 'facts.yml' + # ok: [localhost] => { + # "ansible_facts": { + # "data_source": [ + # { + # "data": [ + # { + # "duplex": "auto", + # "enabled": true, + # "name": "GigabitEthernet0/0", + # "note": [ + # "Connected green wire" + # ], + # "speed": "auto" + # }, + # { + # "description": "Configured by Ansible - Interface 1", + # "duplex": "auto", + # "enabled": true, + # "mtu": 1500, + # "name": "GigabitEthernet0/1", + # "note": [ + # "Connected blue wire", + # "Configured by Paul" + # ], + # "speed": "auto", + # "vifs": [ + # { + # "comment": "Needs reconfiguration", + # "description": "Eth1 - VIF 100", + # "enabled": true, + # "mtu": 400, + # "vlan_id": 100 + # }, + # { + # "description": "Eth1 - VIF 101", + # "enabled": true, + # "vlan_id": 101 + # } + # ] + # }, + # { + # "description": "Configured by Ansible - Interface 2 (ADMIN DOWN)", + # "enabled": false, + # "mtu": 600, + # "name": "GigabitEthernet0/2" + # } + # ], + # "match_key": "name", + # "prefix": "interfaces" + # }, + # { + # "data": [ + # { + # "name": "GigabitEthernet0/0" + # }, + # { + # "name": "GigabitEthernet0/0" + # }, + # { + # "mode": "access", + # "name": "GigabitEthernet0/1", + # "trunk": { + # "allowed_vlans": [ + # "11", + # "12", + # "59", + # "67", + # "75", + # "77", + # "81", + # "100", + # "400-408", + # "411-413", + # "415", + # "418", + # "982", + # "986", + # "988", + # "993" + # ] + # } + # }, + # { + # "mode": "trunk", + # "name": "GigabitEthernet0/2", + # "trunk": { + # "allowed_vlans": [ + # "11", + # "12", + # "59", + # "67", + # "75", + # "77", + # "81", + # "100", + # "400-408", + # "411-413", + # "415", + # "418", + # "982", + # "986", + # "988", + # "993" + # ], + # "encapsulation": "dot1q" + # } + # } + # ], + # "match_key": "name", + # "prefix": "l2_interfaces" + # }, + # { + # "data": [ + # { + # "ipv4": [ + # { + # "address": "192.168.0.2/24" + # } + # ], + # "name": "GigabitEthernet0/0" + # }, + # { + # "name": "GigabitEthernet0/1" + # }, + # { + # "name": "GigabitEthernet0/2" + # }, + # { + # "name": "Loopback888" + # }, + # { + # "name": "Loopback999" + # } + # ], + # "match_key": "name", + # "prefix": "l3_interfaces" + # } + # ] + # }, + # "changed": false + # } + # Read vars_file 'facts.yml' - TASK [Combine all the facts based on match_keys] **************************************************************************************************************** - fatal: [localhost]: FAILED! => { - "msg": "Error when using plugin 'consolidate': 'fail_duplicate' reported Duplicate values in data source 1" - } + # TASK [Combine all the facts based on match_keys] + # fatal: [localhost]: FAILED! => { + # "msg": "Error when using plugin 'consolidate': 'fail_duplicate' reported Duplicate values in data source 1" + # } diff --git a/plugins/filter/consolidate.py b/plugins/filter/consolidate.py index 9e29cbd..975059f 100644 --- a/plugins/filter/consolidate.py +++ b/plugins/filter/consolidate.py @@ -52,9 +52,10 @@ DOCUMENTATION = """ EXAMPLES = r""" # Consolidated facts example -# ------------ +# -------------------------- ##facts.yml + interfaces: - name: GigabitEthernet0/0 enabled: true @@ -137,25 +138,25 @@ l3_interfaces: - name: Loopback999 ##Playbook - vars_files: - - "facts.yml" - tasks: - - name: Build the facts collection - set_fact: - data_source: - - data: "{{ interfaces }}" - match_key: name - prefix: interfaces - - data: "{{ l2_interfaces }}" - match_key: name - prefix: l2_interfaces - - data: "{{ l3_interfaces }}" - match_key: name - prefix: l3_interfaces +vars_files: + - "facts.yml" +tasks: + - name: Build the facts collection + set_fact: + data_source: + - data: "{{ interfaces }}" + match_key: name + prefix: interfaces + - data: "{{ l2_interfaces }}" + match_key: name + prefix: l2_interfaces + - data: "{{ l3_interfaces }}" + match_key: name + prefix: l3_interfaces - - name: Combine all the facts based on match_keys - set_fact: - combined: "{{ data_source|ansible.utils.consolidate(fail_missing_match_value=False) }}" + - name: Combine all the facts based on match_keys + set_fact: + combined: "{{ data_source|ansible.utils.consolidate(fail_missing_match_value=False) }}" ##Output # ok: [localhost] => { @@ -298,7 +299,7 @@ l3_interfaces: # } # Read vars_file 'facts.yml' -# TASK [Combine all the facts based on match_keys] **************************************************************************************************************** +# TASK [Combine all the facts based on match_keys] # ok: [localhost] => { # "ansible_facts": { # "combined": { @@ -520,171 +521,172 @@ l3_interfaces: - name: Loopback999 ##Playbook - vars_files: - - "facts.yml" - tasks: - - name: Build the facts collection - set_fact: - data_source: - - data: "{{ interfaces }}" - match_key: name - prefix: interfaces - - data: "{{ l2_interfaces }}" - match_key: name - prefix: l2_interfaces - - data: "{{ l3_interfaces }}" - match_key: name - prefix: l3_interfaces +vars_files: + - "facts.yml" +tasks: + - name: Build the facts collection + set_fact: + data_source: + - data: "{{ interfaces }}" + match_key: name + prefix: interfaces + - data: "{{ l2_interfaces }}" + match_key: name + prefix: l2_interfaces + - data: "{{ l3_interfaces }}" + match_key: name + prefix: l3_interfaces - - name: Combine all the facts based on match_keys - set_fact: - combined: "{{ data_source|ansible.utils.consolidate(fail_missing_match_value=True) }}" + - name: Combine all the facts based on match_keys + set_fact: + combined: "{{ data_source|ansible.utils.consolidate(fail_missing_match_value=True) }}" ##Output -ok: [localhost] => { - "ansible_facts": { - "data_source": [ - { - "data": [ - { - "duplex": "auto", - "enabled": true, - "name": "GigabitEthernet0/0", - "note": [ - "Connected green wire" - ], - "speed": "auto" - }, - { - "description": "Configured by Ansible - Interface 1", - "duplex": "auto", - "enabled": true, - "mtu": 1500, - "name": "GigabitEthernet0/1", - "note": [ - "Connected blue wire", - "Configured by Paul" - ], - "speed": "auto", - "vifs": [ - { - "comment": "Needs reconfiguration", - "description": "Eth1 - VIF 100", - "enabled": true, - "mtu": 400, - "vlan_id": 100 - }, - { - "description": "Eth1 - VIF 101", - "enabled": true, - "vlan_id": 101 - } - ] - }, - { - "description": "Configured by Ansible - Interface 2 (ADMIN DOWN)", - "enabled": false, - "mtu": 600, - "name": "GigabitEthernet0/2" - } - ], - "match_key": "name", - "prefix": "interfaces" - }, - { - "data": [ - { - "name": "GigabitEthernet0/0" - }, - { - "mode": "access", - "name": "GigabitEthernet0/1", - "trunk": { - "allowed_vlans": [ - "11", - "12", - "59", - "67", - "75", - "77", - "81", - "100", - "400-408", - "411-413", - "415", - "418", - "982", - "986", - "988", - "993" - ] - } - }, - { - "mode": "trunk", - "name": "GigabitEthernet0/2", - "trunk": { - "allowed_vlans": [ - "11", - "12", - "59", - "67", - "75", - "77", - "81", - "100", - "400-408", - "411-413", - "415", - "418", - "982", - "986", - "988", - "993" - ], - "encapsulation": "dot1q" - } - } - ], - "match_key": "name", - "prefix": "l2_interfaces" - }, - { - "data": [ - { - "ipv4": [ - { - "address": "192.168.0.2/24" - } - ], - "name": "GigabitEthernet0/0" - }, - { - "name": "GigabitEthernet0/1" - }, - { - "name": "GigabitEthernet0/2" - }, - { - "name": "Loopback888" - }, - { - "name": "Loopback999" - } - ], - "match_key": "name", - "prefix": "l3_interfaces" - } - ] - }, - "changed": false -} -Read vars_file 'facts.yml' +# ok: [localhost] => { +# "ansible_facts": { +# "data_source": [ +# { +# "data": [ +# { +# "duplex": "auto", +# "enabled": true, +# "name": "GigabitEthernet0/0", +# "note": [ +# "Connected green wire" +# ], +# "speed": "auto" +# }, +# { +# "description": "Configured by Ansible - Interface 1", +# "duplex": "auto", +# "enabled": true, +# "mtu": 1500, +# "name": "GigabitEthernet0/1", +# "note": [ +# "Connected blue wire", +# "Configured by Paul" +# ], +# "speed": "auto", +# "vifs": [ +# { +# "comment": "Needs reconfiguration", +# "description": "Eth1 - VIF 100", +# "enabled": true, +# "mtu": 400, +# "vlan_id": 100 +# }, +# { +# "description": "Eth1 - VIF 101", +# "enabled": true, +# "vlan_id": 101 +# } +# ] +# }, +# { +# "description": "Configured by Ansible - Interface 2 (ADMIN DOWN)", +# "enabled": false, +# "mtu": 600, +# "name": "GigabitEthernet0/2" +# } +# ], +# "match_key": "name", +# "prefix": "interfaces" +# }, +# { +# "data": [ +# { +# "name": "GigabitEthernet0/0" +# }, +# { +# "mode": "access", +# "name": "GigabitEthernet0/1", +# "trunk": { +# "allowed_vlans": [ +# "11", +# "12", +# "59", +# "67", +# "75", +# "77", +# "81", +# "100", +# "400-408", +# "411-413", +# "415", +# "418", +# "982", +# "986", +# "988", +# "993" +# ] +# } +# }, +# { +# "mode": "trunk", +# "name": "GigabitEthernet0/2", +# "trunk": { +# "allowed_vlans": [ +# "11", +# "12", +# "59", +# "67", +# "75", +# "77", +# "81", +# "100", +# "400-408", +# "411-413", +# "415", +# "418", +# "982", +# "986", +# "988", +# "993" +# ], +# "encapsulation": "dot1q" +# } +# } +# ], +# "match_key": "name", +# "prefix": "l2_interfaces" +# }, +# { +# "data": [ +# { +# "ipv4": [ +# { +# "address": "192.168.0.2/24" +# } +# ], +# "name": "GigabitEthernet0/0" +# }, +# { +# "name": "GigabitEthernet0/1" +# }, +# { +# "name": "GigabitEthernet0/2" +# }, +# { +# "name": "Loopback888" +# }, +# { +# "name": "Loopback999" +# } +# ], +# "match_key": "name", +# "prefix": "l3_interfaces" +# } +# ] +# }, +# "changed": false +# } +# Read vars_file 'facts.yml' -TASK [Combine all the facts based on match_keys] **************************************************************************************************************** -fatal: [localhost]: FAILED! => { - "msg": "Error when using plugin 'consolidate': 'fail_missing_match_value' reported Missing match value Loopback999, Loopback888 in data source 0, Missing match value Loopback999, Loopback888 in data source 1" -} +# TASK [Combine all the facts based on match_keys] +# fatal: [localhost]: FAILED! => { +# "msg": "Error when using plugin 'consolidate': 'fail_missing_match_value' reported Missing match value Loopback999, +# Loopback888 in data source 0, Missing match value Loopback999, Loopback888 in data source 1" +# } # Failing on missing match keys # ----------------------------- @@ -772,25 +774,25 @@ l3_interfaces: - inft_name: Loopback999 ##Playbook - vars_files: - - "facts.yml" - tasks: - - name: Build the facts collection - set_fact: - data_source: - - data: "{{ interfaces }}" - match_key: name - prefix: interfaces - - data: "{{ l2_interfaces }}" - match_key: name - prefix: l2_interfaces - - data: "{{ l3_interfaces }}" - match_key: name - prefix: l3_interfaces +vars_files: + - "facts.yml" +tasks: + - name: Build the facts collection + set_fact: + data_source: + - data: "{{ interfaces }}" + match_key: name + prefix: interfaces + - data: "{{ l2_interfaces }}" + match_key: name + prefix: l2_interfaces + - data: "{{ l3_interfaces }}" + match_key: name + prefix: l3_interfaces - - name: Combine all the facts based on match_keys - set_fact: - combined: "{{ data_source|ansible.utils.consolidate(fail_missing_match_key=True) }}" + - name: Combine all the facts based on match_keys + set_fact: + combined: "{{ data_source|ansible.utils.consolidate(fail_missing_match_key=True) }}" ##Output # ok: [localhost] => { @@ -933,9 +935,13 @@ l3_interfaces: # } # Read vars_file 'facts.yml' -# TASK [Combine all the facts based on match_keys] **************************************************************************************************************** +# TASK [Combine all the facts based on match_keys] # fatal: [localhost]: FAILED! => { -# "msg": "Error when using plugin 'consolidate': 'fail_missing_match_key' reported Missing match key 'name' in data source 2 in list entry 0, Missing match key 'name' in data source 2 in list entry 1, Missing match key 'name' in data source 2 in list entry 2, Missing match key 'name' in data source 2 in list entry 3, Missing match key 'name' in data source 2 in list entry 4" +# "msg": "Error when using plugin 'consolidate': 'fail_missing_match_key' reported Missing match +# key 'name' in data source 2 in list entry 0, Missing match key 'name' in data +# source 2 in list entry 1, Missing match key 'name' in data source 2 in list +# entry 2, Missing match key 'name' in data source 2 in list entry 3, Missing +# match key 'name' in data source 2 in list entry 4" # } # Failing on duplicate values in facts @@ -1025,174 +1031,174 @@ l3_interfaces: - name: Loopback999 ##Playbook - vars_files: - - "facts.yml" - tasks: - - name: Build the facts collection - set_fact: - data_source: - - data: "{{ interfaces }}" - match_key: name - prefix: interfaces - - data: "{{ l2_interfaces }}" - match_key: name - prefix: l2_interfaces - - data: "{{ l3_interfaces }}" - match_key: name - prefix: l3_interfaces +vars_files: + - "facts.yml" +tasks: + - name: Build the facts collection + set_fact: + data_source: + - data: "{{ interfaces }}" + match_key: name + prefix: interfaces + - data: "{{ l2_interfaces }}" + match_key: name + prefix: l2_interfaces + - data: "{{ l3_interfaces }}" + match_key: name + prefix: l3_interfaces - - name: Combine all the facts based on match_keys - set_fact: - combined: "{{ data_source|ansible.utils.consolidate(fail_duplicate=True) }}" + - name: Combine all the facts based on match_keys + set_fact: + combined: "{{ data_source|ansible.utils.consolidate(fail_duplicate=True) }}" ##Output -ok: [localhost] => { - "ansible_facts": { - "data_source": [ - { - "data": [ - { - "duplex": "auto", - "enabled": true, - "name": "GigabitEthernet0/0", - "note": [ - "Connected green wire" - ], - "speed": "auto" - }, - { - "description": "Configured by Ansible - Interface 1", - "duplex": "auto", - "enabled": true, - "mtu": 1500, - "name": "GigabitEthernet0/1", - "note": [ - "Connected blue wire", - "Configured by Paul" - ], - "speed": "auto", - "vifs": [ - { - "comment": "Needs reconfiguration", - "description": "Eth1 - VIF 100", - "enabled": true, - "mtu": 400, - "vlan_id": 100 - }, - { - "description": "Eth1 - VIF 101", - "enabled": true, - "vlan_id": 101 - } - ] - }, - { - "description": "Configured by Ansible - Interface 2 (ADMIN DOWN)", - "enabled": false, - "mtu": 600, - "name": "GigabitEthernet0/2" - } - ], - "match_key": "name", - "prefix": "interfaces" - }, - { - "data": [ - { - "name": "GigabitEthernet0/0" - }, - { - "name": "GigabitEthernet0/0" - }, - { - "mode": "access", - "name": "GigabitEthernet0/1", - "trunk": { - "allowed_vlans": [ - "11", - "12", - "59", - "67", - "75", - "77", - "81", - "100", - "400-408", - "411-413", - "415", - "418", - "982", - "986", - "988", - "993" - ] - } - }, - { - "mode": "trunk", - "name": "GigabitEthernet0/2", - "trunk": { - "allowed_vlans": [ - "11", - "12", - "59", - "67", - "75", - "77", - "81", - "100", - "400-408", - "411-413", - "415", - "418", - "982", - "986", - "988", - "993" - ], - "encapsulation": "dot1q" - } - } - ], - "match_key": "name", - "prefix": "l2_interfaces" - }, - { - "data": [ - { - "ipv4": [ - { - "address": "192.168.0.2/24" - } - ], - "name": "GigabitEthernet0/0" - }, - { - "name": "GigabitEthernet0/1" - }, - { - "name": "GigabitEthernet0/2" - }, - { - "name": "Loopback888" - }, - { - "name": "Loopback999" - } - ], - "match_key": "name", - "prefix": "l3_interfaces" - } - ] - }, - "changed": false -} -Read vars_file 'facts.yml' +# ok: [localhost] => { +# "ansible_facts": { +# "data_source": [ +# { +# "data": [ +# { +# "duplex": "auto", +# "enabled": true, +# "name": "GigabitEthernet0/0", +# "note": [ +# "Connected green wire" +# ], +# "speed": "auto" +# }, +# { +# "description": "Configured by Ansible - Interface 1", +# "duplex": "auto", +# "enabled": true, +# "mtu": 1500, +# "name": "GigabitEthernet0/1", +# "note": [ +# "Connected blue wire", +# "Configured by Paul" +# ], +# "speed": "auto", +# "vifs": [ +# { +# "comment": "Needs reconfiguration", +# "description": "Eth1 - VIF 100", +# "enabled": true, +# "mtu": 400, +# "vlan_id": 100 +# }, +# { +# "description": "Eth1 - VIF 101", +# "enabled": true, +# "vlan_id": 101 +# } +# ] +# }, +# { +# "description": "Configured by Ansible - Interface 2 (ADMIN DOWN)", +# "enabled": false, +# "mtu": 600, +# "name": "GigabitEthernet0/2" +# } +# ], +# "match_key": "name", +# "prefix": "interfaces" +# }, +# { +# "data": [ +# { +# "name": "GigabitEthernet0/0" +# }, +# { +# "name": "GigabitEthernet0/0" +# }, +# { +# "mode": "access", +# "name": "GigabitEthernet0/1", +# "trunk": { +# "allowed_vlans": [ +# "11", +# "12", +# "59", +# "67", +# "75", +# "77", +# "81", +# "100", +# "400-408", +# "411-413", +# "415", +# "418", +# "982", +# "986", +# "988", +# "993" +# ] +# } +# }, +# { +# "mode": "trunk", +# "name": "GigabitEthernet0/2", +# "trunk": { +# "allowed_vlans": [ +# "11", +# "12", +# "59", +# "67", +# "75", +# "77", +# "81", +# "100", +# "400-408", +# "411-413", +# "415", +# "418", +# "982", +# "986", +# "988", +# "993" +# ], +# "encapsulation": "dot1q" +# } +# } +# ], +# "match_key": "name", +# "prefix": "l2_interfaces" +# }, +# { +# "data": [ +# { +# "ipv4": [ +# { +# "address": "192.168.0.2/24" +# } +# ], +# "name": "GigabitEthernet0/0" +# }, +# { +# "name": "GigabitEthernet0/1" +# }, +# { +# "name": "GigabitEthernet0/2" +# }, +# { +# "name": "Loopback888" +# }, +# { +# "name": "Loopback999" +# } +# ], +# "match_key": "name", +# "prefix": "l3_interfaces" +# } +# ] +# }, +# "changed": false +# } +# Read vars_file 'facts.yml' -TASK [Combine all the facts based on match_keys] **************************************************************************************************************** -fatal: [localhost]: FAILED! => { - "msg": "Error when using plugin 'consolidate': 'fail_duplicate' reported Duplicate values in data source 1" -} +# TASK [Combine all the facts based on match_keys] +# fatal: [localhost]: FAILED! => { +# "msg": "Error when using plugin 'consolidate': 'fail_duplicate' reported Duplicate values in data source 1" +# } """ from ansible.errors import AnsibleFilterError diff --git a/tests/integration/targets/utils_consolidate/vars/main.yaml b/tests/integration/targets/utils_consolidate/vars/main.yaml index 239ab4d..79a684b 100644 --- a/tests/integration/targets/utils_consolidate/vars/main.yaml +++ b/tests/integration/targets/utils_consolidate/vars/main.yaml @@ -106,4 +106,3 @@ combined_facts: l3_interfaces: name: Loopback999 ospf_interfaces: {} -