Installation¶
Ansible Galaxy¶
Run the following command to install the netbox.netbox collection:
ansible-galaxy collection install netbox.netbox
Follow the official docs to learn more about installation.
Note
Installing Ansible Collections using Git within a requirements.yml
is not supported until Ansible 2.10.
Build From Source¶
Follow these steps to install from source:
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
Using Ansible Collections¶
There are two methods when using a collection in a playbook:
Using the
collections
directive at the play level.Using the Fully Qualified Collection Name (FQCN) of the module, e.g.
netbox.netbox.netbox_device
at the task level.
---
- hosts: "localhost"
collections:
- netbox.netbox
tasks:
- name: "Configure a device in NetBox"
netbox_device:
<.. omitted>
---
- hosts: "localhost"
tasks:
- name: "Configure a device in NetBox"
netbox.netbox.netbox_device:
<.. omitted>
Ansible recommends option 2 by using the FQCN when using Ansible Collections.
You can find more information at the official Ansible docs.
Note
If you are on MacOS and are running into ERROR! A worker was found in a dead state errors
, try running the playbook with env no_proxy='*'
tag in front of the playbook. This is a known issue with MacOS as per this reference: https://github.com/ansible/ansible/issues/32554#issuecomment-642896861
Using Inventory Plugin Within AWX/Tower¶
This will cover the basic usage of the NetBox inventory plugin within this collection.
Define
collections/requirements.yml
within a Git project.AWX/Tower will download the collection on each run. This can be handled differently or excluded if storing Ansible Collections on the AWX/Tower box.
Define
inventory.yml
in Git project that adheres to inventory plugin structure.Add Git project to AWX/Tower as a project.
Create inventory and select
source from project
.Select the AWX/Tower project from Step 2
Select the
inventory.yml
file in the project from Step 3Make sure your Tower installation uses Python 3 or select the proper
ANSIBLE ENVIRONMENT
Click
Save
and sync source.