Skip to content

custom_field

Collection Note

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

ansible-galaxy collection install networktocode.nautobot
Added in version 5.1.0.

You need further requirements to be able to use this module, see the Requirements section for details.

Synopsis

  • Creates or removes custom fields from Nautobot

Requirements

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

Parameters

Parameter Defaults / Choices Comments
advanced_ui
bool
Whether or not to display this field in the advanced tab
Version Added: 5.1.0
api_version
str
API Version Nautobot REST API
Version Added: 4.1.0
content_types
list / elements=str
Content types that this field should be available for
Required if I(state=present) and the custom field does not exist yet
Version Added: 5.1.0
custom_field_choices
dict
List of choices to associate with this custom field (for select or multi-select types).
Version Added: 6.2.0
custom_field_choices.objects List of choices to manage.
custom_field_choices.state Default: merge
Choices: merge, replace, delete
C(merge) adds choices without removing existing ones.
C(replace) enforces exactly the listed choices, removing any extras.
C(delete) removes the listed choices.
default
raw
Default value for this field when editing models
Must be in JSON format
Version Added: 5.1.0
description
str
Description of this field
Also used as the help text when editing models using this custom field
Markdown is supported
Version Added: 5.1.0
filter_logic
str
Choices: disabled, loose, exact Filter logic to apply when filtering models based on this field
Only compatible with I(type=text), I(type=url) and I(type=json)
Version Added: 5.1.0
grouping
str
Human-readable grouping that this custom field belongs to
Version Added: 5.1.0
id
str
The UUID of the object to operate on
Version Added: 5.13.0
key
str
Internal name of this field
Required if I(state=present) and the custom field does not exist yet
Version Added: 5.1.0
label
str
Name of the field as displayed to users
Required if I(state=present) and the custom field does not exist yet
Version Added: 5.1.0
query_params
list / elements=str
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
required
bool
Whether or not a value is required for this field when editing models
Version Added: 5.1.0
state
str
Default: present
Choices: absent, present
Use C(present) or C(absent) for adding or removing.
token
str
required
The token created within Nautobot to authorize API access
Can be omitted if the E(NAUTOBOT_TOKEN) environment variable is configured.
type
str
Choices: text, integer, boolean, date, url, select, multi-select, json, markdown Data type of this field
Required if I(state=present) and the custom field does not exist yet
I(type=select) and I(type=multi-select) require choices to be defined separately with the I(custom_field_choice) module
Version Added: 5.1.0
url
str
required
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
Default: True
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.
validation_maximum
int
Maximum value allowed for this field
Only compatible with I(type=integer)
Version Added: 5.1.0
validation_minimum
int
Minimum value allowed for this field
Only compatible with I(type=integer)
Version Added: 5.1.0
validation_regex
str
Regular expression that this field must match
Only compatible with I(type=text)
Version Added: 5.1.0
weight
int
Position this field should be displayed in
Version Added: 5.1.0

Notes

Note

  • This should be ran with connection C(local) and hosts C(localhost)

Examples

- name: Create custom field within Nautobot with only required information
  networktocode.nautobot.custom_field:
    url: http://nautobot.local
    token: thisIsMyToken
    label: My Custom Field
    key: my_custom_field
    type: text
    state: present

- name: Create custom field within Nautobot with all information
  networktocode.nautobot.custom_field:
    url: http://nautobot.local
    token: thisIsMyToken
    label: My Custom Field
    grouping: My Grouping
    key: my_custom_field
    type: text
    weight: 100
    description: My Description
    required: true
    default: My Default
    filter_logic: loose
    advanced_ui: true
    content_types:
      - dcim.device
    validation_minimum: 0
    validation_maximum: 100
    validation_regex: ^[a-z]+$
    state: present

- name: Create custom field with inline choice associations
  networktocode.nautobot.custom_field:
    url: http://nautobot.local
    token: thisIsMyToken
    label: My Custom Field
    key: my_custom_field
    type: select
    custom_field_choices:
      state: merge
      objects:
        - value: "Choice A"
          weight: 100
        - value: "Choice B"
          weight: 200
    state: present

- name: Delete a custom field by id
  networktocode.nautobot.custom_field:
    url: http://nautobot.local
    token: thisIsMyToken
    id: 00000000-0000-0000-0000-000000000000
    state: absent

Return Values

Key Data Type Description Returned
custom_field dict Serialized object as created or already existent within Nautobot success (when I(state=present))
msg str Message indicating failure or info about what has been achieved always

Authors

  • Joe Wesch (@joewesch)