### Build and Install Netbox Ansible Collection from Source Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/getting_started/installation.md Follow these steps to clone the repository, build the collection locally, and then install it. This method is useful for development or when the latest version is needed. ```bash git clone git@github.com:netbox-community/ansible_modules.git ``` ```bash cd ansible_modules ``` ```bash ansible-galaxy collection build . ``` ```bash ansible-galaxy collection install netbox-netbox*.tar.gz ``` -------------------------------- ### Update Circuit Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_circuit_module.md This example shows how to update an existing circuit by providing additional fields such as status, tenant, installation date, commit rate, description, and comments. The circuit is identified by its 'cid'. ```yaml - name: Update circuit with other fields netbox.netbox.netbox_circuit: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: cid: Test-Circuit-1000 provider: Test Provider circuit_type: Test Circuit Type status: Active tenant: Test Tenant install_date: "2018-12-25" commit_rate: 10000 description: Test circuit comments: "FAST CIRCUIT" state: present ``` -------------------------------- ### Netbox Route Target Module Examples Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/getting_started/contributing/modules/new_module.md Provides examples for creating, updating, and deleting route targets using the netbox_route_target module. ```yaml - name: "Test route target creation/deletion" connection: local hosts: localhost gather_facts: False tasks: - name: Create Route Targets netbox.netbox.netbox_route_target: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: name: "{{ item.name }}" tenant: "Test Tenant" tags: - Schnozzberry loop: - { name: "65000:65001", description: "management" } - { name: "65000:65002", description: "tunnel" } - name: Update Description on Route Targets netbox.netbox.netbox_route_target: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: name: "{{ item.name }}" tenant: "Test Tenant" description: "{{ item.description }}" tags: - Schnozzberry loop: - { name: "65000:65001", description: "management" } - { name: "65000:65002", description: "tunnel" } - name: Delete Route Targets netbox.netbox.netbox_route_target: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: name: "{{ item }}" state: absent loop: - "65000:65001" - "65000:65002" ``` -------------------------------- ### Create NetBox Platform with Config Template Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_platform_module.md This example demonstrates creating a NetBox platform and associating it with a configuration template using its slug. Requires NetBox URL and token. ```yaml - name: Create platform within NetBox with a config template netbox.netbox.netbox_platform: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: name: Test Platform config_template: "my_config_template_slug" state: present ``` -------------------------------- ### Example for creating a VRF with import and export targets Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/getting_started/contributing/modules/update_module.md Demonstrates how to use the 'netbox_vrf' module to create a VRF, including specifying 'import_targets' and 'export_targets' as lists of strings. ```yaml - name: Create vrf with all information netbox_vrf: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: name: Test VRF rd: "65000:1" tenant: Test Tenant enforce_unique: true import_targets: - "65000:65001" export_targets: - "65000:65001" description: VRF description tags: - Schnozzberry state: present ``` -------------------------------- ### Install Python Modules Source: https://github.com/netbox-community/ansible_modules/blob/devel/README.md Installs the necessary Python modules, pytz and pynetbox, required for the Ansible collection. ```bash pip install pytz pip install pynetbox ``` -------------------------------- ### Using Compose for Host Variables Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/nb_inventory_inventory.md This example shows how to use the 'compose' option to populate host variables using data from NetBox. ```yaml plugin: netbox.netbox.nb_inventory compose: foo: last_updated bar: display_name nested_variable: rack.display_name ``` -------------------------------- ### Enable Webhook Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_webhook_module.md This example demonstrates how to enable a webhook using the NetBox Ansible module. Ensure the 'content_types' are correctly specified. ```yaml --- - name: Create a webhook netbox_webhook: netbox_url: http://netbox.example.com netbox_token: thisIsMyToken data: name: "My Webhook" enabled: true content_types: - dcim.device - virtualization.virtualmachine urls: - http://example.com/hook state: present ``` -------------------------------- ### Build and Install Netbox Ansible Collection from Source (Pull Request) Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/getting_started/installation.md This process allows you to test code from a specific pull request before it's merged. It involves cloning the repository, fetching the PR, checking it out, building the collection, and installing it. ```bash git clone git@github.com:netbox-community/ansible_modules.git ``` ```bash cd ansible_modules ``` ```bash git fetch origin pull//head: ``` ```bash git checkout ``` ```bash ansible-galaxy collection build . ``` ```bash ansible-galaxy collection install netbox-netbox*.tar.gz ``` -------------------------------- ### Create NetBox User Group with All Parameters Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_user_group_module.md This example shows how to create a user group in NetBox, including optional parameters like 'description'. ```yaml - name: Create user group with all parameters netbox.netbox.netbox_user_group: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: name: My Group description: The group I made state: present ``` -------------------------------- ### Clone and Start NetBox Docker Instance Source: https://github.com/netbox-community/ansible_modules/blob/devel/CONTRIBUTING.md Clone the `netbox-docker` repository and start a NetBox instance on port 32768. This is a prerequisite for running integration tests locally. ```shell git clone git@github.com:netbox-community/netbox-docker.git cd netbox-docker export VERSION=snapshot docker-compose pull docker-compose up -d ``` -------------------------------- ### Create Power Outlet Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_power_outlet_module.md Example of creating a power outlet in NetBox using the netbox_power_outlet module with only the required parameters. ```yaml - name: "Test NetBox modules" connection: local hosts: localhost gather_facts: false tasks: - name: Create power port within NetBox with only required information netbox.netbox.netbox_power_outlet: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: name: Test Power Outlet device: Test Device state: present ``` -------------------------------- ### Build NetBox Ansible Collection from Source Source: https://github.com/netbox-community/ansible_modules/blob/devel/README.md Builds and installs the NetBox Ansible collection from source code. ```bash git clone git@github.com:netbox-community/ansible_modules.git cd ansible_modules ansible-galaxy collection build . ansible-galaxy collection install netbox-netbox*.tar.gz ``` -------------------------------- ### Device Query Filters Example Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/nb_inventory_inventory.md Demonstrates how to use the `device_query_filters` parameter to specify query strings for devices. Jinja2 templates can be used. ```yaml device_query_filters: - "site=SiteA" - "role=Router" ``` -------------------------------- ### Query Filters Example Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/nb_inventory_inventory.md Demonstrates how to use the `query_filters` parameter to pass query string parameters for devices and VMs. Supports Jinja2 templating. ```yaml query_filters: - "site=SiteA" - "role=Router" ``` -------------------------------- ### Add IP Address with Basic NAT Inside Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/getting_started/how-to-use/advanced.md This example demonstrates adding an IP address with a basic 'nat_inside' specification. It may fail if 'nat_inside' is not unique. ```yaml --- ... tasks: - name: "Add ip address to netbox" netbox.netbox.netbox_ip_address: netbox_url: "http://netbox.local" netbox_token: "thisIsMyToken" data: address: "192.168.10.60/24" vrf: "Test VRF" nat_inside: "192.168.100.1/24" state: present ``` -------------------------------- ### Create Front Port Template (Module Type) Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_front_port_template_module.md This example demonstrates creating a front port template linked to a module type. The 'module_type' parameter is used instead of 'device_type'. ```yaml - name: Create front port template for a module type within NetBox netbox.netbox.netbox_front_port_template: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: name: Test Front Port Template module_type: Test Module Type type: bnc rear_port_template: Test Rear Port Template state: present ``` -------------------------------- ### VM Query Filters Example Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/nb_inventory_inventory.md Demonstrates how to use the `vm_query_filters` parameter to specify query string parameters for virtual machines. This can be used to filter VMs based on various attributes. ```yaml vm_query_filters: - "status=active" - "role=webserver" ``` -------------------------------- ### Create a NetBox Webhook Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_webhook_module.md Example of creating a new webhook in NetBox. This snippet demonstrates setting content types, name, payload URL, and a Jinja2-templated body. ```yaml - name: "Test NetBox webhook module" connection: local hosts: localhost tasks: - name: Create a webhook netbox_webhook: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: content_types: - dcim.device name: Example Webhook type_create: true payload_url: https://payload.url/ body_template: !unsafe >- {{ data }} ``` -------------------------------- ### Generate Ansible Documentation Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/getting_started/contributing/modules/update_module.md Commands to set up the development environment and generate documentation for the Ansible Netbox collection. This includes installing dependencies and running the documentation generation script. ```bash ❯ poetry shell && poetry install ❯ ./hacking/make-docs.sh ``` -------------------------------- ### Create Device with Tags and Local Context Data Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_device_module.md This example shows how to create a device and assign tags and local context data. Tags are provided as a YAML list, and local context data can include custom fields like 'bgp'. ```yaml - name: Create device with tags netbox.netbox.netbox_device: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: name: Another Test Device device_type: C9410R device_role: Core Switch site: Main local_context_data: bgp: "65000" tags: - Schnozzberry state: present ``` -------------------------------- ### Add Device to Device Bay Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_device_bay_module.md Example of adding a device into an existing device bay. This involves specifying the parent device, bay name, and the device to be installed. The state is set to 'absent' to indicate the action of adding a device to the bay, which might seem counter-intuitive but is how the module handles this specific operation. ```yaml - name: Add device into device bay netbox.netbox.netbox_device_bay: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: device: Test Nexus One name: "Device Bay One" description: "First child" installed_device: Test Nexus Child One state: absent ``` -------------------------------- ### Create Virtual Machine with Tags Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_virtual_machine_module.md This snippet demonstrates creating a virtual machine and assigning tags. Tags should be provided as a YAML list. Ensure the `site` is also specified if required by your NetBox configuration. ```yaml - name: Create virtual machine with tags netbox_virtual_machine: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: name: Another Test Virtual Machine cluster: test cluster site: Test Site tags: - Schnozzberry state: present ``` -------------------------------- ### Install NetBox Ansible Collection from requirements.yml Source: https://github.com/netbox-community/ansible_modules/blob/devel/README.md Installs the NetBox Ansible collection by referencing it in a requirements.yml file. ```yaml collections: - name: netbox.netbox ``` -------------------------------- ### Create a NetBox Prefix with Options Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_prefix_module.md Shows how to create a prefix with numerous specified options, including site, VRF, tenant, VLAN details, status, role, description, and tags. Tags should be defined as a YAML list. ```yaml - name: Create prefix with several specified options netbox.netbox.netbox_prefix: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: family: 4 prefix: 10.156.32.0/19 site: Test Site vrf: Test VRF tenant: Test Tenant vlan: name: Test VLAN site: Test Site tenant: Test Tenant vlan_group: Test Vlan Group status: Reserved prefix_role: Network of care description: Test description is_pool: true tags: - Schnozzberry state: present ``` -------------------------------- ### Install Specific Version of NetBox Ansible Collection Source: https://github.com/netbox-community/ansible_modules/blob/devel/README.md Installs a specific version of the NetBox Ansible collection, e.g., version 3.19.1. ```bash ansible-galaxy collection install netbox.netbox:==3.19.1 ``` -------------------------------- ### Ansible Module Failure Example Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/getting_started/how-to-use/modules.md This example shows a typical Ansible task failure message, indicating that a required field ('device_role') was missing for the operation. ```bash failed: [localhost] (item={'unit': 2, 'type': 'nexus-child'}) => {"ansible_loop_var": "item", "changed": false, "item": {"type": "nexus-child", "unit": 2}, "msg": "{\"device_role\":[\"This field is required.\"]}"} ``` -------------------------------- ### Create NetBox Site with All Parameters Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_site_module.md Shows how to create a NetBox site using all available parameters, including status, region, site group, tenant, contact information, and geographical coordinates. Requires NetBox URL and token. ```yaml - name: Create site with all parameters netbox.netbox.netbox_site: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: name: Test - California status: Planned region: Test Region site_group: Test Site Group tenant: Test Tenant facility: EquinoxCA7 asn: 65001 time_zone: America/Los Angeles description: This is a test description 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@changednumber.com slug: test-california comments: "### Placeholder" state: present ``` -------------------------------- ### Create Tenant with All Parameters Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_tenant_module.md Use this comprehensive snippet to create a tenant with all available parameters, including tenant group, description, comments, slug, and tags. This allows for detailed configuration of the tenant. ```yaml - name: Create tenant with all parameters netbox_tenant: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: name: Tenant ABC tenant_group: Very Special Tenants description: ABC Incorporated comments: '### This tenant is super cool' slug: tenant_abc tags: - tagA - tagB - tagC state: present ``` -------------------------------- ### Create VLAN with All Information Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_vlan_module.md Use this example to create a VLAN in NetBox with a comprehensive set of parameters, including site, VLAN group, tenant, status, role, description, and tags. This ensures all available attributes are configured. ```yaml - name: Create vlan with all information netbox_vlan: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: name: Test VLAN vid: 400 site: Test Site vlan_group: Test VLAN Group tenant: Test Tenant status: Deprecated vlan_role: Test VLAN Role description: Just a test tags: - Schnozzberry state: present ``` -------------------------------- ### Install Netbox Ansible Collection via Ansible Galaxy Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/getting_started/installation.md Use this command to install the official netbox.netbox collection from Ansible Galaxy. Ensure you are using Ansible 2.10 or later for collection support. ```bash ansible-galaxy collection install netbox.netbox ``` -------------------------------- ### Create L2VPN with full configuration Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_l2vpn_module.md Use this snippet to create an L2VPN with all available parameters, including identifier, import/export targets, tenant, description, and tags. This provides a comprehensive setup for your L2VPN. ```yaml - name: Create L2VPN with all required information netbox.netbox.netbox_l2vpn: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: name: Test L2VPN type: vpls identifier: 43256 import_targets: - "65000:1" export_targets: - "65000:2" tenant: Test Tenant description: Just a test tags: - Schnozzberry state: present ``` -------------------------------- ### Create an IP Address and a Journal Entry Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_journal_entry_module.md This example demonstrates how to first create an IP address and then create a journal entry associated with that IP address. It requires NetBox URL and Token to be configured. The journal entry is created only if the IP address creation was successful. ```yaml - name: "Test NetBox Module" hosts: localhost connection: local gather_facts: false module_defaults: group/netbox.netbox.netbox: netbox_url: MYURL netbox_token: MYTOKEN tasks: - name: Create an IP Address netbox.netbox.netbox_ip_address: data: address: 192.168.8.14/24 register: ip - name: Create a journal entry netbox.netbox.netbox_journal_entry: data: assigned_object_type: ipam.ipaddress assigned_object_id: "{{ ip.ip_address.id }}" kind: success comments: | This is a journal entry when: ip.changed ``` -------------------------------- ### Run Ansible Module Development Commands Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/getting_started/contributing/modules/new_module.md Execute these commands from the root of your Ansible collection to set up the environment, install dependencies, and generate documentation. This process includes creating a collection archive and installing necessary collections. ```bash ❯ poetry shell && poetry install ❯ ./hacking/make-docs.sh ``` ```bash rm: tests/output: No such file or directory rm: .pytest_cache: No such file or directory Using /Users/myohman/cloned-repos/ansible_modules/ansible.cfg as config file Created collection for netbox.netbox at /Users/myohman/cloned-repos/ansible_modules/netbox-netbox-2.0.0.tar.gz Starting galaxy collection install process [WARNING]: The specified collections path '/Users/myohman/cloned-repos/ansible_modules' is not part of the configured Ansible collections paths '/Users/myohman/.ansible/collections:/usr/share/ansible/collections'. The installed collection won't be picked up in an Ansible run. Process install dependency map Starting collection install process Installing 'netbox.netbox:2.0.0' to '/Users/myohman/cloned-repos/ansible_modules/ansible_collections/netbox/netbox' netbox.netbox (2.0.0) was installed successfully Installing 'ansible.netcommon:1.4.1' to '/Users/myohman/cloned-repos/ansible_modules/ansible_collections/ansible/netcommon' Downloading https://galaxy.ansible.com/download/ansible-netcommon-1.4.1.tar.gz to /Users/myohman/.ansible/tmp/ansible-local-4390k59zwzli/tmp5871aum5 ansible.netcommon (1.4.1) was installed successfully Installing 'community.general:1.3.4' to '/Users/myohman/cloned-repos/ansible_modules/ansible_collections/community/general' Downloading https://galaxy.ansible.com/download/community-general-1.3.4.tar.gz to /Users/myohman/.ansible/tmp/ansible-local-4390k59zwzli/tmp5871aum5 community.general (1.3.4) was installed successfully Installing 'google.cloud:1.0.1' to '/Users/myohman/cloned-repos/ansible_modules/ansible_collections/google/cloud' Downloading https://galaxy.ansible.com/download/google-cloud-1.0.1.tar.gz to /Users/myohman/.ansible/tmp/ansible-local-4390k59zwzli/tmp5871aum5 google.cloud (1.0.1) was installed successfully Installing 'community.kubernetes:1.1.1' to '/Users/myohman/cloned-repos/ansible_modules/ansible_collections/community/kubernetes' Downloading https://galaxy.ansible.com/download/community-kubernetes-1.1.1.tar.gz to /Users/myohman/.ansible/tmp/ansible-local-4390k59zwzli/tmp5871aum5 community.kubernetes (1.1.1) was installed successfully ERROR:antsibull:error=Cannot find plugin:func=get_ansible_plugin_info:mod=antsibull.docs_parsing.ansible_internal:plugin_name=netbox.netbox.netbox_interface:plugin_type=module|Error while extracting documentation. Will not document this plugin. ``` -------------------------------- ### Delete Webhook Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_webhook_module.md This example demonstrates how to delete a webhook by setting the 'state' to 'absent'. ```yaml --- - name: Delete a webhook netbox_webhook: netbox_url: http://netbox.example.com netbox_token: thisIsMyToken data: name: "My Webhook" state: absent ``` -------------------------------- ### Create Module Type (Full Info) Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_module_type_module.md This example demonstrates creating a module type with all available data fields, including the part number. It's useful for comprehensive module type definitions. ```yaml - name: "Test NetBox modules" connection: local hosts: localhost gather_facts: false tasks: - name: Create module type within NetBox netbox.netbox.netbox_module_type: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: model: ws-test-3750 manufacturer: Test Manufacturer part_number: ws-3750g-v2 state: present ``` -------------------------------- ### Disable Webhook Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_webhook_module.md This example shows how to disable a webhook. The 'enabled' parameter is set to 'false'. ```yaml --- - name: Disable a webhook netbox_webhook: netbox_url: http://netbox.example.com netbox_token: thisIsMyToken data: name: "My Webhook" enabled: false state: present ``` -------------------------------- ### Create IP Address with Options Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_ip_address_module.md Creates an IP address with various specified options including VRF, tenant, status, role, description, and tags. Tags should be a YAML list. ```yaml - name: Create IP address with several specified options netbox.netbox.netbox_ip_address: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: address: 192.168.1.20 vrf: Test tenant: Test Tenant status: Reserved role: Loopback description: Test description tags: - Schnozzberry state: present ``` -------------------------------- ### Create NetBox Token (All Parameters) Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_token_module.md This example shows how to create a NetBox token with all available parameters, including description, write enablement, and expiration date. The `expires` field should be in ISO 8601 format. ```yaml - name: Create token with all parameters netbox.netbox.netbox_token: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: user: TestUser key: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa description: The test token write_enabled: false expires: 2024-08-26T14:49:01.345000+00:00 state: present ``` -------------------------------- ### INI Configuration for Cache Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/nb_inventory_inventory.md Example of how to set the cache parameter to false in an Ansible inventory configuration file. ```ini [inventory] cache = false ``` -------------------------------- ### Create Rack with Rack Group (Pre NetBox v2.11) Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_rack_module.md This example demonstrates creating a rack that includes a 'rack_group' parameter, suitable for NetBox versions prior to 2.11. Ensure the 'site' and 'rack_group' exist. ```yaml - name: Create rack within NetBox with only required information - Pre 2.11 netbox.netbox.netbox_rack: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: name: Test rack site: Test Site rack_group: Test Rack Group state: present ``` -------------------------------- ### Delete Rack from NetBox Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_rack_module.md This example shows how to remove a rack from NetBox by specifying its 'name' and setting the 'state' to 'absent'. ```yaml - name: Delete rack within netbox netbox.netbox.netbox_rack: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: name: Test Rack state: absent ``` -------------------------------- ### Create NetBox Contact (All Parameters) Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_contact_module.md Use this example to create a contact in NetBox with all available parameters, including name, title, phone, email, contact groups, and tags. Requires connection 'local' and hosts 'localhost'. ```yaml - name: Create contact with all parameters netbox.netbox.netbox_contact: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: name: contact ABC title: Mr Contact phone: 123456789 email: contac@contact.com contact_groups: - Group 1 - Group 2 tags: - tagA - tagB - tagC state: present ``` -------------------------------- ### Use netbox.netbox.netbox_virtual_disk Module Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_virtual_disk_module.md Demonstrates how to specify the netbox.netbox.netbox_virtual_disk module in an Ansible playbook. Ensure the collection is installed and requirements are met. ```yaml netbox.netbox.netbox_virtual_disk ``` -------------------------------- ### Use netbox_module_bay module in a playbook Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_module_bay_module.md Specify the netbox.netbox.netbox_module_bay module when using it within an Ansible playbook. Ensure the collection is installed. ```yaml netbox.netbox.netbox_module_bay ``` -------------------------------- ### Create Virtual Machine (Required Info) Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_virtual_machine_module.md Use this snippet to create a virtual machine in NetBox with only the essential parameters. Ensure NetBox URL and token are correctly configured. ```yaml - name: "Test NetBox modules" connection: local hosts: localhost gather_facts: false tasks: - name: Create virtual machine within NetBox with only required information netbox_virtual_machine: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: name: Test Virtual Machine cluster: test cluster state: present ``` -------------------------------- ### Delete a NetBox Webhook Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_webhook_module.md Example of deleting a webhook from NetBox. This snippet uses the 'absent' state to remove the specified webhook. ```yaml - name: Delete the webhook netbox_webhook: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: name: Example Webhook type_create: true type_delete: true payload_url: https://payload.url/ body_template: !unsafe >- {{ data }} state: absent ``` -------------------------------- ### Create NetBox Permission with All Parameters Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_permission_module.md This snippet demonstrates creating a NetBox permission using all available parameters, including name, description, enabled status, multiple actions, object types, and constraints. This provides granular control over the permission's configuration. ```yaml - name: Create permission with all parameters netbox.netbox.netbox_permission: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: name: My permission description: The permission I made enabled: false actions: - view - add - change - delete - extreme_administration object_types: - vpn.tunneltermination - wireless.wirelesslan constraints: id: 1 state: present ``` -------------------------------- ### Create VLAN Group with VID Ranges Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_vlan_group_module.md Use this example to create a VLAN group and define specific Video Interface Device (VID) ranges. This is useful for organizing VLANs within specific numerical bands. ```yaml - name: Create vlan group within NetBox with vid_ranges netbox_vlan_group: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: name: Test vlan group vid_ranges: [ [1300, 1329], [1, 2] ] state: present ``` -------------------------------- ### Delete Power Outlet Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_power_outlet_module.md Example of deleting a power outlet from NetBox using the netbox_power_outlet module by setting the state to absent. ```yaml - name: Delete power port within netbox netbox.netbox.netbox_power_outlet: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: name: Test Power Outlet device: Test Device state: absent ``` -------------------------------- ### Delete NetBox Platform Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_platform_module.md This example shows how to delete a platform from NetBox using its name. Requires NetBox URL and token. ```yaml - name: Delete platform within netbox netbox.netbox.netbox_platform: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: name: Test Platform state: absent ``` -------------------------------- ### Create and Apply Config Context Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_config_context_module.md Use this snippet to create a new configuration context and apply it to specified sites with a default weight. ```yaml - name: "Test NetBox config_context module" connection: local hosts: localhost gather_facts: false tasks: - name: Create config context and apply it to sites euc1-az1, euc1-az2 with the default weight of 1000 netbox.netbox.netbox_config_context: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: name: "dns_nameservers-quadnine" description: "9.9.9.9" data: "{ \"dns\": { \"nameservers\": [ \"9.9.9.9\" ] } }" sites: [euc1-az1, euc1-az2] ``` -------------------------------- ### Use netbox_cluster module in a playbook Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_cluster_module.md Demonstrates how to use the netbox.netbox.netbox_cluster module within an Ansible playbook. This requires the netbox.netbox collection to be installed. ```yaml --- - name: Manage NetBox Clusters hosts: localhost connection: local tasks: - name: Create a cluster netbox.netbox.netbox_cluster: netbox_url: "https://netbox.example.com" netbox_token: "0123456789abcdef0123456789abcdef01234567" data: name: "MyCluster" type: "docker" state: "present" register: cluster_creation - name: Update a cluster netbox.netbox.netbox_cluster: netbox_url: "https://netbox.example.com" netbox_token: "0123456789abcdef0123456789abcdef01234567" data: name: "MyCluster" description: "Updated description" state: "present" register: cluster_update - name: Delete a cluster netbox.netbox.netbox_cluster: netbox_url: "https://netbox.example.com" netbox_token: "0123456789abcdef0123456789abcdef01234567" data: name: "MyCluster" state: "absent" register: cluster_deletion ``` -------------------------------- ### Ansible Tower Credential Injection Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/nb_inventory_inventory.md Example of how to inject NetBox API credentials as environment variables for use within Ansible Tower. ```yaml env: NETBOX_API: '{{ NETBOX_API }}' NETBOX_TOKEN: '{{ NETBOX_TOKEN }}' ``` -------------------------------- ### Create Virtual Disk Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_virtual_disk_module.md This snippet demonstrates how to create a virtual disk using the netbox_virtual_disk module. Ensure connection is set to 'local' and hosts to 'localhost'. Tags should be defined as a YAML list. ```yaml - name: "Test NetBox virtual disk module" connection: local hosts: localhost gather_facts: false tasks: - name: Create virtual disk netbox_virtual_disk: data: virtual_machine: test100 name: disk0 size: 50 state: present ``` -------------------------------- ### Update a NetBox Webhook Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_webhook_module.md Example of updating an existing webhook to enable the type_delete event. This snippet shows how to modify webhook properties. ```yaml - name: Update the webhook to run on delete netbox_webhook: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: name: Example Webhook type_create: true type_delete: true payload_url: https://payload.url/ body_template: !unsafe >- {{ data }} ``` -------------------------------- ### Create Device Bay Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_device_bay_module.md Example of creating a device bay in NetBox using the netbox_device_bay module. Requires NetBox URL, token, and data including device and bay name. Use 'present' state to create. ```yaml - name: "Test NetBox modules" connection: local hosts: localhost gather_facts: false tasks: - name: Create device bay within NetBox with only required information netbox.netbox.netbox_device_bay: netbox_url: http://netbox.local netbox_token: thisIsMyToken data: device: Test Nexus One name: "Device Bay One" state: present ``` -------------------------------- ### Use netbox_wireless_link module in a playbook Source: https://github.com/netbox-community/ansible_modules/blob/devel/docs/plugins/netbox_wireless_link_module.md Demonstrates how to specify the netbox.netbox.netbox_wireless_link module within an Ansible playbook. Ensure the collection is installed and requirements are met. ```yaml netbox.netbox.netbox_wireless_link ```