python-nb2an
Port variant v13
Summary Netbox to Ansible config comparison tool (3.13)
BROKEN
Package version 0.9.11
Homepage https://github.com/hardaker/nb2an
Keywords python
Maintainer Python Automaton
License Not yet specified
Other variants v12
Ravenports Buildsheet | History
Ravensource Port Directory | History
Last modified 11 NOV 2024, 23:28:05 UTC
Port created 08 JAN 2023, 04:18:24 UTC
Subpackage Descriptions
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!
Configuration Switches (platform-specific settings discarded)
PY312 OFF Build using Python 3.12 PY313 ON Build using Python 3.13
Package Dependencies by Type
Build (only) python313:dev:std
python-pip:single:v13
autoselect-python:single:std
Build and Runtime python313:primary:std
Runtime (only) python-ansible:single:v13
python-rich:single:v13
python-ruamel.yaml:single:v13
python-requests:single:v13
python-pyaml:single:v13
Download groups
main mirror://PYPIWHL/a8/c9/a5bfae136e81e817069892be792fca7d7091684968b92af820b4f40dfc6f
Distribution File Information
9e8343be643825189af66ea47c729a9b4978a9944a1d87493ac839e9e7b33fb7 17473 nb2an-0.9.11-py3-none-any.whl
Ports that require python-nb2an:v13
No other ports depend on this one.