Ansible - remove dictionary with specific key value from list - ansible

I have data structure as below in example.
My goal is to get a list of users who belong to group group_1. And that's what I am able to do (as in the example).
But additionally, I want to get rid of group_2 in User_1. And I can't do that.
Below ansible playbook and its result:
- hosts: localhost
vars:
search_name: "group_1"
users:
- user_name: "User_1"
email: "user1#mail.com"
login: "user.1"
groups:
- name: group_1
servers:
- server:
name: 'SERVER-01'
ip: '192.168.x.x'
port: 5656
- server:
name: 'SERVER-02'
ip: '192.168.x.x'
port: 5656
- name: group_2
servers:
- server:
name: 'SERVER-03'
ip: '192.168.x.x'
port: 5656
- server:
name: 'SERVER-01'
ip: '192.168.x.x'
port: 5656
- server:
name: 'SERVER-02'
ip: '192.168.x.x'
port: 5656
- user_name: "User_2"
email: "user2#mail.com"
login: "user.2"
groups:
- name: group_1
servers:
- server:
name: 'SERVER-01'
ip: '192.168.x.x'
port: 5656
- server:
name: 'SERVER-02'
ip: '192.168.x.x'
port: 5656
- user_name: "User_3"
email: "user3#mail.com"
login: "user.3"
groups:
- name: group_3
servers:
- server:
name: 'SERVER-03'
ip: '192.168.x.x'
port: 5656
tasks:
- name: Initialize an empty list for servers
set_fact:
filtered_users: []
- name: Filter users by group name
set_fact:
filtered_users: "{{ users | json_query(query) }}"
vars:
query: "[? groups[? name==`group_1`]] | []"
- name: Display users
debug:
msg: "{{ filtered_users }}"
Result
{
"email": "user1#mail.com",
"groups": [
{
"name": "group_1",
"servers": [
{
"server": {
"ip": "192.168.x.x",
"name": "SERVER-01",
"port": 5656
}
},
{
"server": {
"ip": "192.168.x.x",
"name": "SERVER-02",
"port": 5656
}
}
]
},
{
"name": "group_2",
"servers": [
{
"server": {
"ip": "192.168.x.x",
"name": "SERVER-03",
"port": 5656
}
},
{
"server": {
"ip": "192.168.x.x",
"name": "SERVER-01",
"port": 5656
}
},
{
"server": {
"ip": "192.168.x.x",
"name": "SERVER-02",
"port": 5656
}
}
]
}
],
"login": "user.1",
"user_name": "User_1"
},
{
"email": "user2#mail.com",
"groups": [
{
"name": "group_1",
"servers": [
{
"server": {
"ip": "192.168.x.x",
"name": "SERVER-01",
"port": 5656
}
},
{
"server": {
"ip": "192.168.x.x",
"name": "SERVER-02",
"port": 5656
}
}
]
}
],
"login": "user.2",
"user_name": "User_2"
}
]
How can this be achieved?

JMESPath is fine for simple questions, but is hard to wrap one's head around complex stuff, especially since your ultimate question involves selectively building up a new "user" dict (or mutating the var, it's hard to tell which outcome you'd want). If you want the original data mutated, just remove the | combine({}) that clones the user dict
- name: Filter users by group name
set_fact:
filtered_users: >-
{%- set results = [] -%}
{%- for ur in users -%}
{%- set u = ur | combine({}) -%}
{%- set g1 = u.groups | selectattr("name", "eq", search_name) -%}
{%- if g1 | length > 0 -%}
{%- set _ = u.update({"groups": g1}) -%}
{%- set _ = results.append(u) -%}
{%- endif -%}
{%- endfor -%}
{{ results }}

Related

Merge 2 hashes recursively with jinja2/ansible

I'm trying to merge 2 hashes in ansible, but I'm running into problems. The hash is mostly merged, but the lists inside are not.
I'm using the combine filter for the merge:
config_hash: "{{ inventory_config | combine(host_config, recursive=True, list_merge='append_rp') }}"
Here are the two hashes/dicts I'd like to merge:
inventory_config:
exoscale:
inventory_name: test_inventory
security_groups:
- name: rancher
state: present
rules:
- port: 22
cidr: "1.2.3.4/32"
type: egress
- port: 80
cidr: "0.0.0.0/32"
type: egress
host_config:
exoscale:
name: host
disk_size: 25 GiB
security_groups:
- name: rancher
state: added
rules:
- port: 21
cidr: "1.2.3.4/32"
type: ingress
- port: 8080
cidr: "0.0.0.0/32"
type: ingress
The result:
TASK [debug] *******************************************************************
ok: [instance] => {
"config_hash": {
"exoscale": {
"disk_size": "25 GiB",
"inventory_name": "test_inventory",
"name": "host",
"security_groups": [
{
"name": "rancher",
"rules": [
{
"cidr": "1.2.3.4/32",
"port": 22,
"type": "egress"
},
{
"cidr": "0.0.0.0/32",
"port": 80,
"type": "egress"
}
],
"state": "present"
},
{
"name": "rancher",
"rules": [
{
"cidr": "1.2.3.4/32",
"port": 21,
"type": "ingress"
},
{
"cidr": "0.0.0.0/32",
"port": 8080,
"type": "ingress"
}
],
"state": "added"
}
]
}
}
}
The result I wanted:
"config_hash": {
"exoscale": {
"disk_size": "25 GiB",
"inventory_name": "test_inventory",
"name": "host",
"security_groups": [
{
"name": "rancher",
"rules": [
{
"cidr": "1.2.3.4/32",
"port": 22,
"type": "egress"
},
{
"cidr": "0.0.0.0/32",
"port": 80,
"type": "egress"
},
{
"cidr": "1.2.3.4/32",
"port": 21,
"type": "ingress"
},
{
"cidr": "0.0.0.0/32",
"port": 8080,
"type": "ingress"
}
],
"state": "added"
},
]
}
}
I tried some other options, and it seems that "list_merge='append_rp'" can combine lists of simple items but not hashes.
Any ideas? Thanks for the help!
Your question is complex, i suggest you to use a custom filter:
you create a folder filter_plugins in your playbook folder (i have named the file myfilters.py and the filter custom)
myfilters.py in folder filter_plugins:
#!/usr/bin/python
class FilterModule(object):
def filters(self):
return {
'custom': self.custom
}
def custom(self, invent, host):
isecu = invent['exoscale']['security_groups']
hsecu = host['exoscale']['security_groups']
inventory_name = invent['exoscale']['inventory_name']
name = host['exoscale']['name']
disk_size = host['exoscale']['disk_size']
security_groups = []
inames_present = [elem['name'] for elem in isecu]
# if you have present and added in inventory_config uncomment next lines
# inames_present = []
# inames_added = []
# for elem in isecu:
# if elem['state'] == 'present':
# inames_present.append(elem['name'])
# else:
# inames_added.append(elem['name'])
for it in hsecu:
secuname = it['name']
state = it['state']
if secuname in inames_present:
if state == 'present': #overwrite data
rules = it['rules']
else: #merge
rules = it['rules'] + isecu[inames_present.index(secuname)]['rules']
else:
rules = it['rules']
state = 'added'
security_groups.append({'name': secuname, 'rules': rules, 'state': state})
result = {'exoscale': {'disk_size': disk_size, 'name': name, 'inventory_name': inventory_name, 'security_groups': security_groups}}
#print(result)
return result
the playbook:
---
- hosts: localhost
vars:
inventory_config:
exoscale:
inventory_name: test_inventory
security_groups:
- name: rancher
state: present
rules:
- port: 22
cidr: "1.2.3.4/32"
type: egress
- port: 80
cidr: "0.0.0.0/32"
type: egress
host_config:
exoscale:
name: host
disk_size: 25 GiB
security_groups:
- name: rancher
state: added
rules:
- port: 21
cidr: "1.2.3.4/32"
type: ingress
- port: 8080
cidr: "0.0.0.0/32"
type: ingress
tasks:
- name: set variable
set_fact:
config_hash: "{{ inventory_config | custom(host_config) }}"
- name: Display
debug:
var: config_hash
result:
ok: [localhost] => {
"config_hash": {
"exoscale": {
"disk_size": "25 GiB",
"inventory_name": "test_inventory",
"name": "host",
"security_groups": [
{
"name": "rancher",
"rules": [
{
"cidr": "1.2.3.4/32",
"port": 21,
"type": "ingress"
},
{
"cidr": "0.0.0.0/32",
"port": 8080,
"type": "ingress"
},
{
"cidr": "1.2.3.4/32",
"port": 22,
"type": "egress"
},
{
"cidr": "0.0.0.0/32",
"port": 80,
"type": "egress"
}
],
"state": "added"
}
]
}
}
}
You have an idea how to use a custom filter in ansible.
You just adapt the code python.

How to loop in Ansible over registerd result and selecting specific node?

i am registering a result from a specific SQL query:
- name: Output Result
debug:
var: result.query_result[0]
I get a long list that looks like this:
{
"result": {
"changed": true,
"failed": false,
"query_result": [
[
{
"C": "",
"CHID": "",
"DESCRIPTION": "",
"EXPECTED_VALUE": "",
"HOST": "",
"SAP_NOTE": "",
"VALUE": ""
},
{
"C": "",
"CHID": "M0005",
"DESCRIPTION": "Generated with",
"EXPECTED_VALUE": "",
"HOST": "",
"SAP_NOTE": "1969700",
"VALUE": "SQL: \\HANA_Configuration_MiniChecks\\\"\""
}
]
],
"rc": 0,
"stderr": "",
"stderr_lines": []
}
}
How can I output only this part if he exists:
{
"C": "",
"CHID": "M0005",
"DESCRIPTION": "Generated with",
"EXPECTED_VALUE": "",
"HOST": "",
"SAP_NOTE": "1969700",
"VALUE": "SQL: \\HANA_Configuration_MiniChecks\\\"\""
}
The location of the above node can change, so i can't specifically target it.
you can use json_query to filter the item that has key/value: "CHID": "M0005"
full playbook example to demonstrate:
---
- hosts: localhost
gather_facts: false
vars:
query_result:
- C: ''
CHID: ''
DESCRIPTION: ''
EXPECTED_VALUE: ''
HOST: ''
SAP_NOTE: ''
VALUE: ''
- C: ''
CHID: M0005
DESCRIPTION: Generated with
EXPECTED_VALUE: ''
HOST: ''
SAP_NOTE: '1969700'
VALUE: 'SQL: \HANA_Configuration_MiniChecks\""'
- C: ''
CHID: 22M00051231
DESCRIPTION: Generated with2121
EXPECTED_VALUE: ''
HOST: ''
SAP_NOTE: '1969700444'
VALUE: '444SQL: \HANA_Configuration_MiniChecks\""'
tasks:
- set_fact:
filtered_item: "{{ query_result | json_query('[?CHID == `M0005`]') }}"
- debug:
var: filtered_item
in your case, the json_query should look like:
- set_fact:
filtered_item: "{{ result.query_result | json_query('[?CHID == `M0005`]') }}"
Please note that if the list may have multiple items matching the condition, they will all be added to the filtered_item. To make sure you get only the first, you can pass the result to first:
- set_fact:
filtered_item: "{{ query_result | json_query('[?CHID == `M0005`]') | first }}"

How to replace value for a key in a json file using ansible

Below is my sample.json file
"abc": {
"host": "xyz",
"version": "3.0.0-4"
},
"def": {
"host": "xyz",
"version": "3.0.0-4"
},
"ghi": {
"host": "xyz",
"version": "4.1.0-4"
},
How to modify value of version key for some of the blocks and not modify for other blocks?
For eg. in above case I want to modify version value for abc and def block but not for ghi block using ansible.
Expected o/p :
"abc": {
"host": "xyz",
"version": "4.0.0-4" // modified value
},
"def": {
"host": "xyz",
"version": "4.0.0-4" // modified value
},
"ghi": {
"host": "xyz",
"version": "4.1.0-4" //not modified
},
Read the JSON data into a dictionary, e.g.
- include_vars:
file: sample.json
name: sample
gives
sample:
abc:
host: xyz
version: 3.0.0-4
def:
host: xyz
version: 3.0.0-4
ghi:
host: xyz
version: 4.1.0-4
To change the version of items abc and def some structure is needed. For example, let's create a dictionary of the new versions
new_version:
abc: "4.0.0-4"
def: "4.0.0-4"
Then the task below
- set_fact:
sample: "{{ sample|combine({item.key: item.value|
combine({'version': new_version[item.key]})}) }}"
loop: "{{ sample|dict2items }}"
when: item.key in new_version
vars:
new_version:
abc: "4.0.0-4"
def: "4.0.0-4"
gives
sample:
abc:
host: xyz
version: 4.0.0-4
def:
host: xyz
version: 4.0.0-4
ghi:
host: xyz
version: 4.1.0-4
The logic of the task might be different. For example "Change the lower versions only". In this case, the data and code are simpler, e.g.
new_version: "4.0.0-4"
The task below gives the same result
- set_fact:
sample: "{{ sample|combine({item.key: item.value|
combine({'version': new_version})}) }}"
loop: "{{ sample|dict2items }}"
when: item.value.version is version(new_version, 'lt')
vars:
new_version: "4.0.0-4"
Then, replace the file, e.g.
- copy:
dest: sample.json
content: "{{ sample|to_json }}"
gives
shell> cat sample.json
{"abc": {"host": "xyz", "version": "4.0.0-4"}, "def": {"host": "xyz", "version": "4.0.0-4"}, "ghi": {"host": "xyz", "version": "4.1.0-4"}}
Here is a small function which takes as arguments:
obj: Json object
keys: Array of keys affected
prop: The property to be changed
value: The new value of the property
let myObj = {
"abc": { "host": "xyz", "version": "3.0.0-4" },
"def": { "host": "xyz", "version": "3.0.0-4" },
"ghi": { "host": "xyz", "version": "4.1.0-4" }
}
const repla = (obj, keys, prop, value) => {
return Object.keys(obj).map((key) => {
if(keys.indexOf(key) > -1) {
return {[key]: {...obj[key], [prop] : value}}
} else {
return {[key] : obj[key]};
}
})
}
const newObj = repla(myObj, ["abc", "def"], "version", "newData");
console.log(newObj)

Correct way to join a new Windows guest to a domain when deployed form a template

I am attempting to automate the deployment of a Windows guest in a VMware environment and I have been quite able to do so as long as I am happy with having to manually add it to the domain, which I am not. I have tried using the vmware_client customization and it does not appear to even be applied.
Ansible 2.9
Red Hat 8
YML
---
- hosts: all
gather_facts: false
vars_files:
- group_vars/all
- build_info/vars
tasks:
- debug:
var: "{{ dusername }}"
- name: Clone a virtual machine from Windows template and customize
vmware_guest:
annotation: "This machine was built from a template through a process triggered by an ansible playbook"
hostname: "{{ hostname }}"
username: "{{ username }}"
password: "{{ password }}"
validate_certs: "{{ validate_certs }}"
datacenter: "{{ datacenter }}"
cluster: "{{ cluster }}"
folder: "{{ folder }}"
name: "{{ bname }}"
template: "{{ template }}"
datastore: "{{ datastore}}"
state: poweredon
networks:
- name: "{{ bnetworks.netname }}"
ip: "{{ bnetworks.ip }}"
netmask: "{{ bnetworks.netmask }}"
gateway: "{{ bnetworks.gateway }}"
domain: "{{ bnetworks.domain }}"
start_connected: yes
dns_servers: "{{bnetworks.dns_servers}}"
dns_suffix: "{{bnetworks.dns_suffix}}"
customization:
hostname: "{{ bname }}"
domainadmin: "{{ dusername }}"
domainadminpassword: "{{ dpassword }}"
joindomain: "{{ bnetworks.domain }}"
fullname: "{{ ladminname }}"
wait_for_ip_address: yes
wait_for_customization: yes
with_dict: "{{ bnetworks }}"
delegate_to: localhost'
The result
{
"changed": true,
"instance": {
"module_hw": true,
"hw_name": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"hw_power_status": "poweredOn",
"hw_guest_full_name": "Microsoft Windows Server 2016 or later (64-bit)",
"hw_guest_id": "windows9Server64Guest",
"hw_product_uuid": "4227f81c-1b25-13fd-45f2-d9399408a5f6",
"hw_processor_count": 2,
"hw_cores_per_socket": 1,
"hw_memtotal_mb": 8192,
"hw_interfaces": [
"eth0"
],
"hw_datastores": [
"na2-tntr02-dat"
],
"hw_files": [
"[na2-tntr02-dat] ********/********.vmx",
"[na2-tntr02-dat] ********/********.nvram",
"[na2-tntr02-dat] ********/********.vmsd",
"[na2-tntr02-dat] ********/********.vmxf",
"[na2-tntr02-dat] ********/********.vmdk"
],
"hw_esxi_host": "na2-devesx01.********",
"hw_guest_ha_state": true,
"hw_is_template": false,
"hw_folder": "/NA2/vm/GLOBAL OPERATIONS/Storage",
"hw_version": "vmx-13",
"instance_uuid": "5027d0ef-7a89-73a6-1da9-6e15df083592",
"guest_tools_status": "guestToolsRunning",
"guest_tools_version": "11269",
"guest_question": null,
"guest_consolidation_needed": false,
"ipv4": "10.6.6.10",
"ipv6": null,
"annotation": "This machine was built from a template through a process triggered by an ansible playbook",
"customvalues": {},
"snapshots": [],
"current_snapshot": null,
"vnc": {},
"moid": "vm-21984",
"vimref": "vim.VirtualMachine:vm-21984",
"hw_cluster": "NA2-NonPROD",
"hw_eth0": {
"addresstype": "assigned",
"label": "Network adapter 1",
"macaddress": "00:50:56:a7:fc:87",
"ipaddresses": [
"fe80::4835:d689:f1a7:6dd4",
"10.6.6.10"
],
"macaddress_dash": "00-50-56-a7-fc-87",
"summary": "DVSwitch: 50 27 7a 36 e1 9e ae 1a-29 5a 4a 79 8d 2b 6f a3",
"portgroup_portkey": "191",
"portgroup_key": "dvportgroup-71"
}
},
"invocation": {
"module_args": {
"annotation": "This machine was built from a template through a process triggered by an ansible playbook",
"hostname": "na2-pdvcva01.********",
"username": "RP4VM#vsphere.local",
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"validate_certs": false,
"datacenter": "NA2",
"cluster": "NA2-NonPROD",
"folder": "/GLOBAL OPERATIONS/Storage",
"name": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"template": "NA2_ZWindows2016STD",
"datastore": "na2-tntr02-dat",
"state": "poweredon",
"networks": [
{
"name": "FIRM_NA|PROD_ap|STORAGE_epg",
"ip": "10.6.6.10",
"netmask": "255.255.255.0",
"gateway": "10.6.6.1",
"domain": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"start_connected": true,
"dns_servers": [
"10.6.2.16",
"10.2.2.17"
],
"dns_suffix": [
"VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"asia.global-legal.com",
"emea.global-legal.com"
],
"type": "static"
}
],
"customization": {
"hostname": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"domainadmin": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"domainadminpassword": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"joindomain": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"fullname": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
},
"wait_for_ip_address": true,
"wait_for_customization": true,
"port": 443,
"is_template": false,
"customvalues": [],
"name_match": "first",
"use_instance_uuid": false,
"disk": [],
"cdrom": [],
"hardware": {},
"force": false,
"state_change_timeout": 0,
"linked_clone": false,
"vapp_properties": [],
"proxy_host": null,
"proxy_port": null,
"uuid": null,
"guest_id": null,
"esxi_hostname": null,
"snapshot_src": null,
"resource_pool": null,
"customization_spec": null,
"convert": null
}
},
"_ansible_no_log": false,
"item": {
"key": "netname",
"value": "FIRM_NA|PROD_ap|STORAGE_epg"
},
"ansible_loop_var": "item",
"_ansible_item_label": {
"key": "netname",
"value": "FIRM_NA|PROD_ap|STORAGE_epg"
},
"_ansible_delegated_vars": {}
}
However the machine does not join the domain. I fully expect a fail because the domain credentials supplied do not have the authority to add the machine to the domain.

Is it possible to set/lookup Ansible facts when play returns multiple values

I have the following playbook in AWX that looks up Infoblox hosts based on their Mac Address and then outputs the information in a more user friendly format.
The current playbook works providing that a single host with that Mac address exists but fails if there are multiple.
---
- hosts: localhost
connection: local
vars:
niosip: ""
niosmac: ""
niosdhcp: ""
nioshostname: ""
niossearchcatagory: "{{ 'name' if searchcatagory == 'Hostname' else 'ipv4addr' if searchcatagory == 'IP Address' else 'mac' if searchcatagory == 'Mac Address'}}"
pre_tasks:
- include_vars:
file: creds.yml
tasks:
- name: fetch host record
set_fact:
host: "{{ lookup('nios', 'record:host', filter={niossearchcatagory: searchcriteria, 'view': 'Internal'}, provider=nios_provider) }}"
- name: Set niosip
set_fact:
niosip: "{{ host.ipv4addrs[0].ipv4addr }}"
nioshostname: "{{ host.name }}"
niosdhcp: "{{ host.ipv4addrs[0].configure_for_dhcp }}"
niosmac: "{{ host.ipv4addrs[0].mac }}"
when: host != [] and host.ipv4addrs[0].mac is defined
- name: Set niosip
set_fact:
niosip: "{{ host.ipv4addrs[0].ipv4addr }}"
nioshostname: "{{ host.name }}"
niosdhcp: "{{ host.ipv4addrs[0].configure_for_dhcp }}"
when: host != [] and host.ipv4addrs[0].mac is undefined
- name: Host not found
debug:
msg: 'Cant find related host'
when: host == []
- name: Display Display Registration Info
debug:
msg:
- Hostname = {{ nioshostname }}
- IP = {{ niosip }}
- Mac Address {{ niosmac }}
- Registered for DHCP = {{ niosdhcp }}
when: host != [] and host.ipv4addrs[0].mac is defined
Variables niossearchcatagory and searchcriteria are passed into the playbook via an AWX Survey.
I've searched possible options around using loops or splitting the output down but I'm really at a loss on the best way to process this.
If the output matches this then the playbook works as expected
{
"changed": false,
"ansible_facts": {
"host": [
{
"_ref": "record:host/ZG5zLmhvc3QkLl9kZWZhdWx0LnVrLmFjLmJoYW0udGVzdC5zbmF0LWF3eHRlc3Q1:snat-awxtest5.test.com/Internal",
"ipv4addrs": [
{
"_ref": "record:host_ipv4addr/ZG5zLmhvc3RfYWRkcmVzcyQuX2RlZmF1bHQudWsuYWMuYmhhbS50ZXN0LnNuYXQtYXd4dGVzdDUuMTQ3LjE4OC4zMS40Lg:192.168.31.4/snat-awxtest5.test.com/Internal",
"configure_for_dhcp": false,
"host": "snat-awxtest5.test.com",
"ipv4addr": "192.168.31.4",
"mac": "10:20:30:40:50:60"
}
],
"name": "snat-awxtest5.test.com",
"view": "Internal"
},
]
},
"_ansible_no_log": false
}
And here's an example of the play returning multiple values
{
"changed": false,
"ansible_facts": {
"host": [
{
"_ref": "record:host/ZG5zLmhvc3QkLl9kZWZhdWx0LnVrLmFjLmJoYW0udGVzdC5zbmF0LWF3eHRlc3Q1:snat-awxtest5.test.com/Internal",
"ipv4addrs": [
{
"_ref": "record:host_ipv4addr/ZG5zLmhvc3RfYWRkcmVzcyQuX2RlZmF1bHQudWsuYWMuYmhhbS50ZXN0LnNuYXQtYXd4dGVzdDUuMTQ3LjE4OC4zMS40Lg:192.168.31.4/snat-awxtest5.test.com/Internal",
"configure_for_dhcp": false,
"host": "snat-awxtest5.test.com",
"ipv4addr": "192.168.31.4",
"mac": "10:20:30:40:50:60"
}
],
"name": "snat-awxtest5.test.com",
"view": "Internal"
},
{
"_ref": "record:host/ZG5zLmhvc3QkLl9kZWZhdWx0LnVrLmFjLmJoYW0udGVzdC5zbmF0LW15d2Vi:snat-myweb.test.com/Internal",
"ipv4addrs": [
{
"_ref": "record:host_ipv4addr/ZG5zLmhvc3RfYWRkcmVzcyQuX2RlZmF1bHQudWsuYWMuYmhhbS50ZXN0LnNuYXQtbXl3ZWIuMTQ3LjE4OC4zMS4yLg:192.168.31.2/snat-myweb.test.com/Internal",
"configure_for_dhcp": false,
"host": "snat-myweb.test.com",
"ipv4addr": "192.168.31.2",
"mac": "10:20:30:40:50:60"
}
],
"name": "snat-myweb.test.com",
"view": "Internal"
},
{
"_ref": "record:host/ZG5zLmhvc3QkLl9kZWZhdWx0LnVrLmFjLmJoYW0udGVzdC5zbmF0LXdlYg:snat-web.test.com/Internal",
"ipv4addrs": [
{
"_ref": "record:host_ipv4addr/ZG5zLmhvc3RfYWRkcmVzcyQuX2RlZmF1bHQudWsuYWMuYmhhbS50ZXN0LnNuYXQtd2ViLjE0Ny4xODguMzEuMy4:192.168.31.3/snat-web.test.com/Internal",
"configure_for_dhcp": false,
"host": "snat-web.test.com",
"ipv4addr": "192.168.31.3",
"mac": "10:20:30:40:50:60"
}
],
"name": "snat-web.test.com",
"view": "Internal"
}
]
},
"_ansible_no_log": false
}
And this results in an error as the variables host.name, host.ipv4addrs etc.. don't exist which I presume is becasue there are multiples.
Any help on how to output each registration would be gratefully received.

Resources