Skip to content

location

Collection Note

This module is part of the networktocode.nautobot collection. To install the collection, use:

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

Synopsis

  • Creates or removes locations from Nautobot

Requirements

The following Python packages are needed on the host that executes this module:

Parameters

Parameter Data Type Environment Variable Comments
api_version str API Version Nautobot REST API
Version Added: 4.1.0
asn int The ASN associated with the location
Version Added: 5.1.0
comments str Comments for the location. This can be markdown syntax
Version Added: 5.1.0
contact_email str Contact email for location
Version Added: 5.1.0
contact_name str Name of contact for location
Version Added: 5.1.0
contact_phone str Contact phone number for location
Version Added: 5.1.0
custom_fields dict Must exist in Nautobot and in key/value format
Version Added: 3.0.0
description str Location description
facility str Data center provider or facility, ex. Equinix NY7
Version Added: 5.1.0
id str Primary Key of the location, used to delete the location. Because of hierarchical nature of locations and name being not unique across locations, it's a user responsibility to query location and pass its id(PK) to the task to delete the location.
latitude str Latitude in decimal format
Version Added: 5.1.0
location_type raw The type of location Required if I(state=present) and does not exist yet
longitude str Longitude in decimal format
Version Added: 5.1.0
name str Name of the location to be created
parent_location raw The parent location this location should be tied to
physical_address str Physical address of location
Version Added: 5.1.0
query_params list 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.
Version Added: 3.0.0
shipping_address str Shipping address of location
Version Added: 5.1.0
state str Use C(present) or C(absent) for adding or removing.
status raw Status of the location Required if I(state=present) and does not exist yet
tags list Any tags that this item may need to be associated with
Version Added: 3.0.0
tenant raw The tenant the location will be assigned to
Version Added: 5.1.0
time_zone str Timezone associated with the location, ex. America/Denver
Version Added: 5.1.0
token
required
str The token created within Nautobot to authorize API access Can be omitted if the E(NAUTOBOT_TOKEN) environment variable is configured.
url
required
str The URL of the Nautobot instance resolvable by the Ansible host (for example: http://nautobot.example.com:8000) Can be omitted if the E(NAUTOBOT_URL) environment variable is configured.
validate_certs raw If C(no), SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. Can be omitted if the E(NAUTOBOT_VALIDATE_CERTS) environment variable is configured.

Notes

Note

  • Tags should be defined as a YAML list
  • This should be ran with connection C(local) and hosts C(localhost)

Examples

- name: "Test Nautobot location module"
  connection: local
  hosts: localhost
  gather_facts: False
  tasks:
    - name: Create location
      networktocode.nautobot.location:
        url: http://nautobot.local
        token: thisIsMyToken
        name: My Location
        status: Active
        location_type:
          name: My Location Type
        state: present

    - name: Delete location
      networktocode.nautobot.location:
        url: http://nautobot.local
        token: thisIsMyToken
        id: "{{ location_to_delete['key'] }}"
        state: absent
      vars:
        location_to_delete: "{{ lookup('networktocode.nautobot.lookup', 'locations', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=\"My Location\" parent_location=\"Location Parent\" location_type=\"Main Type\"') }}"

    - name: Create location with all parameters
      networktocode.nautobot.location:
        url: http://nautobot.local
        token: thisIsMyToken
        name: My Nested Location
        status: Active
        location_type:
          name: My Location Type
        description: My Nested Location Description
        tenant: Test Tenant
        facility: EquinoxCA7
        asn: "65001"
        time_zone: America/Los Angeles
        physical_address: Hollywood, CA, 90210
        shipping_address: Hollywood, CA, 90210
        latitude: "10.100000"
        longitude: "12.200000"
        contact_name: Jenny
        contact_phone: 867-5309
        contact_email: jenny@example.com
        comments: "**This** is a `markdown` comment"
        parent: My Location
        state: present

Return Values

Key Data Type Description Returned
location dict Serialized object as created or already existent within Nautobot on creation
msg str Message indicating failure or info about what has been achieved always

Authors

  • Joe Wesch (@joewesch)