Port variant | v12 |
Summary | Netbox to Ansible config comparison tool (3.12) |
BROKEN | |
Package version | 0.9.11 |
Homepage | https://github.com/hardaker/nb2an |
Keywords | python |
Maintainer | Python Automaton |
License | Not yet specified |
Other variants | v13 |
Ravenports | Buildsheet | History |
Ravensource | Port Directory | History |
Last modified | 15 NOV 2024, 16:08:50 UTC |
Port created | 08 JAN 2023, 04:18:24 UTC |
single | # nb2an: Netbox to Ansible [NetBox] and [Ansible] both require a lot of manual configuration, often with duplicate information. Keeping them in sync can be a daunting challenge. The **nb2an** package provides utilities to map NetBox values to ansible *host_vars* using a simple mapping file. Read the [full documentation online] # Installation You can use *pip* or *pipx* to install the nb2an tools: pipx install nb2an # Usage Updating your ansible data from netbox requires the following steps. ## Step 1: Create a nb2an configuration file *nb2an* tools take a YAML-based master configuration file containing your netbox API token (which you'll need to get from your NetBox instance). In this configuration file you can set a number of variables. Note that some of these can be overridden with command line options. ``` yaml # Your netbox API token: token: YOUR_NETBOX_API_TOKEN # what the API path is for your netbox install api_url: https://netbox/api/ # domain suffix of your ansible FQDNs # (nb2an tools will check NetBox for simple and full names) suffix: .example.com # where th eroot of your ansible code is stored ansible_directory: /home/user/ansible ``` ## Step 2: create a YAML mapping file The *nb-update-ansible* tool is designed to only update variables within your ansible host_vars that you ask it to, leaving everything else (including comments) the same. Note that formatting is overwritten by default, but see below for how to make a patch instead (actually TBD). The YAML file consists of a host_vars YAML structure that you'd like to have updated. Currently this supports only dictionaries, but array support is coming shortly. The value of each variable should be a dotted notation of where to pull the information from in the netbox data for a given device. See the *nb-device* tool below for how to get a dump of a device for easier reading. Here's an example mapping file, that updates or creates information in a *host_info* section and a *netbox_info* section. ``` yaml host_info: serial_number: serial site: site.name location: location.name rack: rack.display position: position netbox_info: id: id site_url: site.url ``` ## Step 3: Run *nb-update-ansible* **Note:** don't forget to check in to your VC (*git*) any outstanding changes you have to your files in *host_vars* before running this tool. $ np-update-ansible -c sample.yml INFO : modifying /home/user/ansible/host_vars/firewall.example.com.yml $ cd /home/user/ansible/host_vars $ git diff diff --git a/host_vars/f1-lab.example.com.yml b/host_vars/f1-lab.example.com.yml --- a/host_vars/f1-lab.example.com.yml +++ b/host_vars/f1-lab.example.com.yml +host_info: + serial_number: 00112233 + site: MIA + location: DC9 Room Q + rack: Rack1 + position: 40 +netbox_info: + id: 37 + device_url: https://netbox/api/device/37/ + site_url: https://netbox/api/dcim/sites/7/ Profit! |
Build (only) |
python312:dev:std python-pip:single:v12 autoselect-python:single:std |
Build and Runtime | python312:primary:std |
Runtime (only) |
python-ansible:single:v12 python-rich:single:v12 python-ruamel.yaml:single:v12 python-requests:single:v12 python-pyaml:single:v12 |
main | mirror://PYPIWHL/a8/c9/a5bfae136e81e817069892be792fca7d7091684968b92af820b4f40dfc6f |
No other ports depend on this one. |