![]() The jsonquery filter lets you query a complex JSON structure. I am only showing a single device corresponding to MSP & DEN site. Filters in Ansible are from Jinja2, and are used for transforming data inside a template expression. To do this you change the filter to be site=den site=-msp. To filter multiple sites, say you wanted to get the devices at both of the sites DEN and MSP. With this you are able to filter many things. The query function does not need the templating language (wrapped in device_role : id : 3 name : Router slug : router url : device_type : display_name : Cisco IOSV id : 3 manufacturer : id : 1 name : Cisco slug : cisco url : model : IOSV slug : iosv url : display_name : den-wan01 face : null id : 4 last_updated : ' T19:55:16.432666Z' local_context_data : null name : den-wan01 parent_device : null platform : id : 2 name : cisco_ios slug : ios url : position : null primary_ip : address : 10.16.0.2/24 family : 4 id : 4 url : primary_ip4 : address : 10.16.0.2/24 family : 4 id : 4 url : primary_ip6 : null rack : null serial : 90Q1VEN47MPBMU2718KJ1 site : id : 4 name : DEN slug : den url : status : label : Active value : active tags : - color : 3f51b5 id : 2 name : snmp_monitoring slug : snmp_monitoring url : tenant : null url : vc_position : null vc_priority : null virtual_chassis : null TASK *************************************************************************************************** ok : => msg : - den-wan01 So I was originally trying to use the Jinja variable template when I was working with the plugin. My methodology for gathering this information is that the plugin is looking to get the Django application (Sites, Devices, IPAM) Environmentįor this demo, here are the versions shown: Component For this post we will use the query method. It helps you to parse JSON content and filter the elements you want. It is a powerful query language to parse JSON content. jsonquery is using the jmespath Query language. The same behavior is also available by using the lookup function, in conjunction with the parameter wantlist=true. As the name suggests, the Ansible jsonquery filter is helping you to query the JSON document and get the elements in the JSON tree structure. This tells Ansible that the result of the lookup should be a type list. The recommended Jinja function to use with this lookup plugin is the query function. ![]() If you wish to use NetBox as your inventory source, you should definitely read my previous post on getting started with the NetBox Inventory Plugin. On top of being helpful in gathering data from NetBox (when it is not your inventory source), but it is extremely helpful in larger NetBox deployments when compared to using the URI module as well. This uses pynetbox to query the NetBox API for the information requested. The NetBox lookup plugin is to get information out of NetBox for use within Ansible. Get Devices - Filtered to a single site.Gathering Sites: TASK 2 Output - Getting Just the Site Names.
0 Comments
Leave a Reply. |