networktocode.nautobot.ip_address module – Creates or removes IP addresses from Nautobot

Note

This module is part of the networktocode.nautobot collection (version 4.5.0).

To install it, use: ansible-galaxy collection install networktocode.nautobot. You need further requirements to be able to use this module, see Requirements for details.

To use it in a playbook, specify: networktocode.nautobot.ip_address.

New in networktocode.nautobot 1.0.0

Synopsis

  • Creates or removes IP addresses from Nautobot

Requirements

The below requirements are needed on the host that executes this module.

  • pynautobot

Parameters

Parameter

Comments

address

string

added in networktocode.nautobot 3.0.0

Required if state is present

api_version

string

added in networktocode.nautobot 4.1.0

API Version Nautobot REST API

assigned_object

dictionary

added in networktocode.nautobot 3.0.0

Definition of the assigned object.

device

string

The device the interface is attached to.

name

string

The name of the interface

virtual_machine

string

The virtual machine the interface is attached to.

custom_fields

dictionary

added in networktocode.nautobot 3.0.0

Must exist in Nautobot and in key/value format

description

string

added in networktocode.nautobot 3.0.0

The description of the interface

dns_name

string

added in networktocode.nautobot 3.0.0

Hostname or FQDN

nat_inside

any

added in networktocode.nautobot 3.0.0

The inside IP address this IP is assigned to

prefix

any

added in networktocode.nautobot 3.0.0

With state present, if an interface is given, it will ensure

that an IP inside this prefix (and vrf, if given) is attached to this interface. Otherwise, it will get the next available IP of this prefix and attach it. With state new, it will force to get the next available IP in this prefix. If an interface is given, it will also force to attach it. Required if state is present or new when no address is given. Unused if an address is specified.

query_params

list / elements=string

added in networktocode.nautobot 3.0.0

This can be used to override the specified values in ALLOWED_QUERY_PARAMS that is defined

in plugins/module_utils/utils.py and provides control to users on what may make

an object unique in their environment.

role

string

added in networktocode.nautobot 3.0.0

state

string

Use present, new or absent for adding, force adding or removing.

present will check if the IP is already created, and return it if true. new will force to create it anyway (useful for anycasts, for example).

Choices:

status

any

added in networktocode.nautobot 3.0.0

The status of the IP address

Required if state=present and does not exist yet

tags

list / elements=any

added in networktocode.nautobot 3.0.0

Any tags that this item may need to be associated with

tenant

any

added in networktocode.nautobot 3.0.0

The tenant that the device will be assigned to

token

string / required

The token created within Nautobot to authorize API access

url

string / required

The URL of the Nautobot instance resolvable by the Ansible host (for example: http://nautobot.example.com:8000)

validate_certs

any

If no, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates.

Default: :ansible-option-default:`true`

vrf

any

added in networktocode.nautobot 3.0.0

VRF that IP address is associated with

Notes

Note

  • Tags should be defined as a YAML list

  • This should be ran with connection local and hosts localhost

Examples

- name: "Test Nautobot IP address module"
  connection: local
  hosts: localhost
  gather_facts: False

  tasks:
    - name: Create IP address within Nautobot with only required information
      networktocode.nautobot.ip_address:
        url: http://nautobot.local
        token: thisIsMyToken
        address: 192.168.1.10
        status: active
        state: present
    - name: Force to create (even if it already exists) the IP
      networktocode.nautobot.ip_address:
        url: http://nautobot.local
        token: thisIsMyToken
        address: 192.168.1.10
        state: new
    - name: Get a new available IP inside 192.168.1.0/24
      networktocode.nautobot.ip_address:
        url: http://nautobot.local
        token: thisIsMyToken
        prefix: 192.168.1.0/24
        state: new
    - name: Delete IP address within nautobot
      networktocode.nautobot.ip_address:
        url: http://nautobot.local
        token: thisIsMyToken
        address: 192.168.1.10
        state: absent
    - name: Create IP address with several specified options
      networktocode.nautobot.ip_address:
        url: http://nautobot.local
        token: thisIsMyToken
        address: 192.168.1.20
        vrf: Test
        tenant: Test Tenant
        status: Reserved
        role: Loopback
        description: Test description
        tags:
          - Schnozzberry
        state: present
    - name: Create IP address and assign a nat_inside IP
      networktocode.nautobot.ip_address:
        url: http://nautobot.local
        token: thisIsMyToken
        address: 192.168.1.30
        vrf: Test
        nat_inside:
          address: 192.168.1.20
          vrf: Test
        assigned_object:
          name: GigabitEthernet1
          device: test100
    - name: Ensure that an IP inside 192.168.1.0/24 is attached to GigabitEthernet1
      networktocode.nautobot.ip_address:
        url: http://nautobot.local
        token: thisIsMyToken
        prefix: 192.168.1.0/24
        vrf: Test
        assigned_object:
          name: GigabitEthernet1
          device: test100
        state: present
    - name: Attach a new available IP of 192.168.1.0/24 to GigabitEthernet1
      networktocode.nautobot.ip_address:
        url: http://nautobot.local
        token: thisIsMyToken
        prefix: 192.168.1.0/24
        vrf: Test
        assigned_object:
          name: GigabitEthernet1
          device: test100
        state: new

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

ip_address

dictionary

Serialized object as created or already existent within Nautobot

Returned: on creation

msg

string

Message indicating failure or info about what has been achieved

Returned: always

Authors

  • Mikhail Yohman (@FragmentedPacket)

  • Anthony Ruhier (@Anthony25)