jonjozwiak / bluecat-ipam-rest Goto Github PK
View Code? Open in Web Editor NEWAnsible role for Bluecat IPAM using the REST API
License: GNU General Public License v3.0
Ansible role for Bluecat IPAM using the REST API
License: GNU General Public License v3.0
I was looking into the response you get from "getHostRecordsByHint". The thing is that the json response is an array: (note the brackets)
"json": [
{
"id": 720154,
"name": "ID-TY-DEV20",
"properties": "absoluteName=ID-TY-DEV20.com|parentId=112918|parentType=Zone|reverseRecord=true|addresses=192.168.4.5|addressIds=720153|",
"type": "HostRecord"
}
],
In your case you are only interested in the first element [0] (start=0&count=1)
So the trick is to use a filter and then just take the first element out (no need to iterate over array for this):
dnsId: "{{ (host_record_output.content|from_json)[0].id }}"
This will give a cleaner code more Ansible native eg:
- name: Check if host record already exists
url:
url: "{{ bluecat_url }}/Services/REST/v1/getHostRecordsByHint?containerId={{ viewId }}&start=0&count=1&options="hint=^{{ target_hostname }}$|retrieveFields=false"
--> lines of code <--
register: host_record_output
- name: Set DNS Entry Fact
set_fact:
dnsId: "{{ (host_record_output.content|from_json)[0].id }}"
--> lines of code <--
Hope this helps :-)
@jonjozwiak thanks for pushing up this role:-) I have one minor thought regarding snippet below. Is there a reason that you don't split the string instead of regexp?
Something like this:
{{ network_record_output.json.properties.split("|")[7] | replace("gateway=", "") }}
# Hacky way to get address from properties="CIDR=192.168.240.0/24|locationInherited=true|allowDuplicateHost=disable|inheritAllowDuplicateHost=true|pingBeforeAssign=disable|inheritPingBeforeAssign=true|gateway=192.168.240.1|inheritDefaultDomains=true|inheritDefaultView=true|inheritDNSRestrictions=true|"
- name: Set Gateway Fact
set_fact:
ipGateway: "{{ network_record_output.json.properties | regex_replace('^.*gateway=', '') | regex_replace('\\|.*', '') }}"
Regards
Fredrik
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.