Git Product home page Git Product logo

bluecat-ipam-rest's Introduction

Role Name

This role works with Bluecat Address Manager (Proteus) REST API to acquire and release IP addresses and their associated DNS names. It does a quick deploy rather than full deploy. It takes a target hostname as input and sets the following variables while acquiring and IP which can be used in subsequent plays:

ipAddress
ipNetmask
ipGateway

This role was tested with Bluecat Address Manager 8.1.0

Requirements

This role uses the 'ipaddr' filter to return the subnet mask for the given CIDR. This requires the python netaddr module (from python-netaddr / python3-netaddr RPM). Alternatively you could remove the ipNetmask section from the role.

Role Variables

Variables can be set overall in the top section of a playbook or in the include_role section as shown in the playbook example. variables in the top section override those in the tasks section.

# Bluecat Address Manager Credentials of User with API access 
bluecat_username: "apiuser"
bluecat_password: "apipassword"
bluecat_url: "https://bcn_proteus.example.com"

# Configuration and view details from Bluecat
bluecat_configuration_name: "Example"
bluecat_dns_view: "internal"

# Properties to pass through to the bluecat API acquire IP call (only one can be defined)
address_properties: "offset=192.168.30.15"          # Start from this address
address_properties: "skip=192.168.30.1-192.168.30.15"        # Skip these addresses
address_properties: "|excludeDHCPRange=true"        # Skip DHCP range
address_properties: "skip=10.10.10.128-10.10.11.200,10.10.11.210|offset=10.10.10.100|excludeDHCPRange=true|" # All in one

# Choose no if using self signed certs.  yes if certs are valid
validate_certs: "no"

# Determine whether to acquire or release an IP/DNS name.  Default is present.  Options are:
#    Create or Acquire IP/DNS:  present, acquire 
#    Lookup IP by hostname: 	get, lookup
#    Release IP/DNS:		absent, release
state: "present"

# Host name to acquire or release 
target_hostname: "host.example.com"

# The CIDR of the network to acquire an IP
bluecat_network_cidr: "192.168.30.0/24"

Dependencies

Example Playbook

NOTE- vars up top override include_role vars below. If you are setting a variable in the include_role in tasks, don't state it in the vars at the top

- name: Deploy and retire IP addresses
  hosts: localhost
  vars:
    bluecat_username: "apiuser"
    bluecat_password: "apipassword"
    bluecat_url: "https://bcn_proteus.example.com"
    bluecat_configuration_name: "Example"
    bluecat_network_cidr: "192.168.30.0/24"     # The CIDR of the network to acquire an IP
    bluecat_dns_view: "internal"
    address_properties: "offset=192.168.30.15"          # Start from this address
    #address_properties: "skip=192.168.30.1-192.168.30.15"        # Skip these addresses
    #address_properties: "|excludeDHCPRange=true"        # Skip DHCP range
    validate_certs: "no"        # Choose no if using self signed certs.. 
  gather_facts: false
  tasks:
    - name: Get IP Address 
      include_role: 
        name: jonjozwiak.bluecat-ipam-rest 
      vars: 
        target_hostname: "ansibletest.example.com"

    - name: Do something with the IP address returned 
      debug: var=ipAddress

    - name: Get IP Address
      include_role:
        name: jonjozwiak.bluecat-ipam-rest
      vars:
        target_hostname: "ansibletest2.example.com"

    - name: Do something with the IP address returned 
      debug: msg="IP address: <{{ipAddress}}>.  Netmask: <{{ipNetmask}}>. Gateway: <{{ipGateway}}>."

    - name: Release IP Address 
      include_role:
        name: jonjozwiak.bluecat-ipam-rest
      vars:
        target_hostname: "ansibletest.example.com"
        state: absent

    - name: Release IP Address 
      include_role:
        name: jonjozwiak.bluecat-ipam-rest
      vars:
        target_hostname: "ansibletest2.example.com"
        state: absent

License

GPLv3

Author Information

Jon Jozwiak

bluecat-ipam-rest's People

Contributors

jonjozwiak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

bluecat-ipam-rest's Issues

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

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

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.