networktocode.nautobot.device module – Create, update or delete devices within Nautobot

Note

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

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install networktocode.nautobot.

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

New in version 1.0.0: of networktocode.nautobot

Synopsis

  • Creates, updates or removes devices from Nautobot

Requirements

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

  • pynautobot

Parameters

Parameter

Comments

asset_tag

string

added in 3.0.0 of networktocode.nautobot

Asset tag that is associated to the device

cluster

raw

added in 3.0.0 of networktocode.nautobot

Cluster that the device will be assigned to

comments

string

added in 3.0.0 of networktocode.nautobot

Comments that may include additional information in regards to the device

custom_fields

dictionary

added in 3.0.0 of networktocode.nautobot

must exist in Nautobot

device_role

raw

added in 3.0.0 of networktocode.nautobot

Required if state=present and the device does not exist yet

device_type

raw

added in 3.0.0 of networktocode.nautobot

Required if state=present and the device does not exist yet

face

string

added in 3.0.0 of networktocode.nautobot

Required if rack is defined

Choices:

  • Front

  • front

  • Rear

  • rear

local_context_data

dictionary

added in 3.0.0 of networktocode.nautobot

Arbitrary JSON data to define the devices configuration variables.

name

string / required

added in 3.0.0 of networktocode.nautobot

The name of the device

platform

raw

added in 3.0.0 of networktocode.nautobot

The platform of the device

position

integer

added in 3.0.0 of networktocode.nautobot

The position of the device in the rack defined above

primary_ip4

raw

added in 3.0.0 of networktocode.nautobot

Primary IPv4 address assigned to the device

primary_ip6

raw

added in 3.0.0 of networktocode.nautobot

Primary IPv6 address assigned to the device

query_params

list / elements=string

added in 3.0.0 of networktocode.nautobot

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.

rack

raw

added in 3.0.0 of networktocode.nautobot

The name of the rack to assign the device to

serial

string

added in 3.0.0 of networktocode.nautobot

Serial number of the device

site

raw

added in 3.0.0 of networktocode.nautobot

Required if state=present and the device does not exist yet

state

string

Use present or absent for adding or removing.

Choices:

  • absent

  • present ← (default)

status

raw

added in 3.0.0 of networktocode.nautobot

The status of the device

Required if state=present and the device does not exist yet

tags

list / elements=raw

added in 3.0.0 of networktocode.nautobot

Any tags that the device may need to be associated with

tenant

raw

added in 3.0.0 of networktocode.nautobot

The tenant that the device will be assigned to

token

string / required

The token created within Nautobot to authorize API access

url

string / required

URL of the Nautobot instance resolvable by Ansible control host

validate_certs

raw

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

Default: “yes”

vc_position

integer

added in 3.0.0 of networktocode.nautobot

Position in the assigned virtual chassis

vc_priority

integer

added in 3.0.0 of networktocode.nautobot

Priority in the assigned virtual chassis

virtual_chassis

raw

added in 3.0.0 of networktocode.nautobot

Virtual chassis the device will be assigned to

Notes

Note

  • Tags should be defined as a YAML list

  • This should be ran with connection local and hosts localhost

Examples

- name: "Test Nautobot modules"
  connection: local
  hosts: localhost
  gather_facts: False

  tasks:
    - name: Create device within Nautobot with only required information
      networktocode.nautobot.device:
        url: http://nautobot.local
        token: thisIsMyToken
        name: Test Device
        device_type: C9410R
        device_role: Core Switch
        site: Main
        status: active
        state: present

    - name: Create device within Nautobot with empty string name to generate UUID
      networktocode.nautobot.device:
        url: http://nautobot.local
        token: thisIsMyToken
        name: ""
        device_type: C9410R
        device_role: Core Switch
        site: Main
        status: active
        state: present

    - name: Delete device within nautobot
      networktocode.nautobot.device:
        url: http://nautobot.local
        token: thisIsMyToken
        name: Test Device
        state: absent

    - name: Create device with tags
      networktocode.nautobot.device:
        url: http://nautobot.local
        token: thisIsMyToken
        name: Another Test Device
        device_type: C9410R
        device_role: Core Switch
        site: Main
        status: active
        local_context_data:
          bgp: "65000"
        tags:
          - Schnozzberry
        state: present

    - name: Update the rack and position of an existing device
      networktocode.nautobot.device:
        url: http://nautobot.local
        token: thisIsMyToken
        name: Test Device
        rack: Test Rack
        position: 10
        face: Front
        state: present

Return Values

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

Key

Description

device

dictionary

Serialized object as created or already existent within Nautobot

Returned: success (when state=present)

msg

string

Message indicating failure or info about what has been achieved

Returned: always

Authors

  • Mikhail Yohman (@FragmentedPacket)

  • David Gomez (@amb1s1)