Skip to content

Instantly share code, notes, and snippets.

@larsks
Created November 24, 2021 12:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save larsks/ba1b0566b85e436a33398cd6a88fd9e3 to your computer and use it in GitHub Desktop.
Save larsks/ba1b0566b85e436a33398cd6a88fd9e3 to your computer and use it in GitHub Desktop.

If you run:

ansible-playbook playbook.yml  -e target_address='10.216.14.8'

You get as output:

PLAY [localhost] ***************************************************************

TASK [read json file] **********************************************************
ok: [localhost]

TASK [find block with address 10.216.14.8] *************************************
ok: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] => {
    "msg": "ID is 12eac420-b7b3-4e24-b90d-40490fc1f92b"
}

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
[
{
"DHCPRelayStatus":"DISABLED",
"DPI":"INHERITED",
"EVPNEnabled":true,
"ID":"12eac420-b7b3-4e24-b90d-40490fc1f92b",
"IPType":"IPV4",
"IPv6Address":null,
"IPv6Gateway":null,
"PATEnabled":"INHERITED",
"VXLANECMPEnabled":false,
"accessRestrictionEnabled":false,
"address":"10.216.14.8",
"advertise":true,
"associatedDomainID":"069af96c-5c38-47e6-8a46-ac89fd914625",
"associatedMulticastChannelMapID":null,
"associatedSharedNetworkResourceID":null,
"children":null,
"creationDate":1563890071000,
"customerID":1004279548,
"description":"Shurooq-WBX-DC1",
"domainServiceLabel":"1958156351",
"dynamicIpv6Address":true,
"encryption":"INHERITED",
"entityScope":"ENTERPRISE",
"entityState":null,
"externalID":null,
"gateway":"10.216.14.10",
"gatewayMACAddress":"68:54:ED:00:95:EF",
"ingressReplicationEnabled":false,
"lastUpdatedBy":"145b5797-a92d-4015-b2c0-cfaf0d4ff9f4",
"lastUpdatedDate":1564064792000,
"maintenanceMode":"DISABLED",
"multiHomeEnabled":false,
"multicast":"INHERITED",
"name":"WBX1-205-14-05",
"netmask":"255.255.255.252",
"owner":"145b5797-a92d-4015-b2c0-cfaf0d4ff9f4",
"parentID":"3b2f748e-8055-4933-ae86-8b95291dea32",
"parentType":"zone",
"policyGroupID":242747888,
"proxyARP":false,
"public":false,
"resourceType":"STANDARD",
"routeDistinguisher":"65534:29014",
"routeTarget":"65534:57349",
"serviceID":981822105,
"splitSubnet":false,
"subnetVLANID":null,
"templateID":null,
"underlay":false,
"underlayEnabled":"INHERITED",
"useGlobalMAC":"DISABLED",
"vnId":3097790
},
{
"DHCPRelayStatus":"DISABLED",
"DPI":"INHERITED",
"EVPNEnabled":true,
"ID":"07d45552-638c-426f-8dea-496ce9c8f969",
"IPType":"IPV4",
"IPv6Address":null,
"IPv6Gateway":null,
"PATEnabled":"INHERITED",
"VXLANECMPEnabled":false,
"accessRestrictionEnabled":false,
"address":"10.216.14.12",
"advertise":true,
"associatedDomainID":"0e27f78f-f96c-4d8e-8d41-d6896c08db73",
"associatedMulticastChannelMapID":null,
"associatedSharedNetworkResourceID":null,
"children":null,
"creationDate":1565105833000,
"customerID":1540605623,
"description":"DC1-WBX1",
"domainServiceLabel":"770035841",
"dynamicIpv6Address":true,
"encryption":"INHERITED",
"entityScope":"ENTERPRISE",
"entityState":null,
"externalID":null,
"gateway":"10.216.14.14",
"gatewayMACAddress":"68:54:ED:00:94:E0",
"ingressReplicationEnabled":false,
"lastUpdatedBy":"145b5797-a92d-4015-b2c0-cfaf0d4ff9f4",
"lastUpdatedDate":1565105833000,
"maintenanceMode":"DISABLED",
"multiHomeEnabled":false,
"multicast":"INHERITED",
"name":"WBX1-206-14-206",
"netmask":"255.255.255.252",
"owner":"145b5797-a92d-4015-b2c0-cfaf0d4ff9f4",
"parentID":"c7a30d4b-7490-4f69-af33-df76783e0cc6",
"parentType":"zone",
"policyGroupID":1120936612,
"proxyARP":false,
"public":false,
"resourceType":"STANDARD",
"routeDistinguisher":"65534:1067",
"routeTarget":"65534:43966",
"serviceID":2062248853,
"splitSubnet":false,
"subnetVLANID":null,
"templateID":null,
"underlay":false,
"underlayEnabled":"INHERITED",
"useGlobalMAC":"DISABLED",
"vnId":8822031
},
{
"DHCPRelayStatus":"DISABLED",
"DPI":"INHERITED",
"EVPNEnabled":true,
"ID":"8cd5bfd2-2ac3-4245-9a9a-b6be7bff90bb",
"IPType":"IPV4",
"IPv6Address":null,
"IPv6Gateway":null,
"PATEnabled":"INHERITED",
"VXLANECMPEnabled":false,
"accessRestrictionEnabled":false,
"address":"10.216.14.16",
"advertise":true,
"associatedDomainID":"3af2624f-85b7-4bc8-89d2-a1234b49370c",
"associatedMulticastChannelMapID":null,
"associatedSharedNetworkResourceID":null,
"children":null,
"creationDate":1565104880000,
"customerID":1795606749,
"description":"DC1-WBX1",
"domainServiceLabel":"1339489179",
"dynamicIpv6Address":true,
"encryption":"INHERITED",
"entityScope":"ENTERPRISE",
"entityState":null,
"externalID":null,
"gateway":"10.216.14.18",
"gatewayMACAddress":"68:54:ED:00:0A:05",
"ingressReplicationEnabled":false,
"lastUpdatedBy":"145b5797-a92d-4015-b2c0-cfaf0d4ff9f4",
"lastUpdatedDate":1565104880000,
"maintenanceMode":"DISABLED",
"multiHomeEnabled":false,
"multicast":"INHERITED",
"name":"WBX1-207-14-207",
"netmask":"255.255.255.252",
"owner":"145b5797-a92d-4015-b2c0-cfaf0d4ff9f4",
"parentID":"22952023-e2ec-4307-a69b-2468fb243e35",
"parentType":"zone",
"policyGroupID":1924715936,
"proxyARP":false,
"public":false,
"resourceType":"STANDARD",
"routeDistinguisher":"65534:40588",
"routeTarget":"65534:43804",
"serviceID":125591962,
"splitSubnet":false,
"subnetVLANID":null,
"templateID":null,
"underlay":false,
"underlayEnabled":"INHERITED",
"useGlobalMAC":"DISABLED",
"vnId":7182479
}
]
- hosts: localhost
gather_facts: false
tasks:
- name: read json file
set_fact:
data: "{{ lookup('file', 'data.json')|from_json }}"
- name: find block with address {{ target_address }}
set_fact:
target: >-
{{ data | selectattr('address', 'eq', target_address) | first }}
- debug:
msg: "ID is {{ target.ID }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment