Git Product home page Git Product logo

bluecat-ipam-rest's Issues

Use uri instead of curl

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 :-)

Just a thought.

@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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.