ansible.utils.param_list_compare (4.0.0) — filter

Generate the final param list combining/comparing base and provided parameters.

| "added in version" 2.4.0 of ansible.utils"

Authors: Rohit Thakur (@rohitthakur2590)

Install collection

Install with ansible-galaxy collection install ansible.utils:==4.0.0


Add to requirements.yml

  collections:
    - name: ansible.utils
      version: 4.0.0

Description

Generate the final list of parameters after comparing with base list and provided/target list of params/bangs.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- set_fact:
    base: ['1', '2', '3', '4', ' 5']
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- set_fact:
    target: ['!all', '2', '4']
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Get final list of parameters
  register: result
  set_fact:
    final_params: "{{ base | param_list_compare(target) }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# TASK [Target list] **********************************************************
# ok: [localhost] => {
#     "msg": {
#         "actionable": [
#             "2",
#             "4"
#         ],
#         "unsupported": []
#     }
# }

- set_fact:
    base: ['1', '2', '3', '4', '5']
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Get final list of parameters
  register: result
  set_fact:
    final_params: "{{ base|param_list_compare(target=['2', '7', '8']) }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# TASK [Get final list of parameters] ********************************************
# ok: [localhost] => {
#     "ansible_facts": {
#         "final_params": {
#             "actionable": [
#                 "2"
#             ],
#             "unsupported": [
#                 "7",
#                 "8"
#             ]
#         }
#     },
#     "changed": false
# }

# Network Specific Example
# -----------
- set_fact:
    ios_resources:
      - "acl_interfaces"
      - "acls"
      - "bgp_address_family"
      - "bgp_global"
      - "interfaces"
      - "l2_interfaces"
      - "l3_interfaces"
      - "lacp"
      - "lacp_interfaces"
      - "lag_interfaces"
      - "lldp_global"
      - "lldp_interfaces"
      - "logging_global"
      - "ospf_interfaces"
      - "ospfv2"
      - "ospfv3"
      - "prefix_lists"
      - "route_maps"
      - "static_routes"
      - "vlans"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- set_fact:
    target_resources:
      - '!all'
      - 'vlan'
      - 'bgp_global'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Get final list of target resources/params
  register: result
  set_fact:
    network_resources: "{{ ios_resources|param_list_compare(target_resources) }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Target list of network resources
  debug:
    msg: "{{ network_resources }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# TASK [Target list of network resources] *******************************************************************************************************************
# ok: [localhost] => {
#     "msg": {
#         "actionable": [
#             "bgp_global",
#             "vlans"
#         ],
#         "unsupported": []
#     }
# }

- name: Get final list of target resources/params
  register: result
  set_fact:
    network_resources: "{{ ios_resources|param_list_compare(target=['vla', 'ntp_global', 'logging_global']) }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Target list of network resources
  debug:
    msg: "{{ network_resources }}"

Inputs

    
base:
    description: Specify the base list.
    elements: str
    type: list

target:
    description: Specify the target list.
    elements: str
    type: list

Outputs

actionable:
  description: list of combined params
  type: list
unsupported:
  description: list of unsupported params
  type: list