# Buildsheet autogenerated by ravenadm tool -- Do not edit. NAMEBASE= python-nb2an VERSION= 0.9.11 KEYWORDS= python VARIANTS= v11 v12 SDESC[v11]= Netbox to Ansible config comparison tool (3.11) SDESC[v12]= Netbox to Ansible config comparison tool (3.12) HOMEPAGE= https://github.com/hardaker/nb2an CONTACT= Python_Automaton[python@ironwolf.systems] DOWNLOAD_GROUPS= main SITES[main]= PYPIWHL/a8/c9/a5bfae136e81e817069892be792fca7d7091684968b92af820b4f40dfc6f DISTFILE[1]= nb2an-0.9.11-py3-none-any.whl:main DF_INDEX= 1 SPKGS[v11]= single SPKGS[v12]= single OPTIONS_AVAILABLE= PY311 PY312 OPTIONS_STANDARD= none VOPTS[v11]= PY311=ON PY312=OFF VOPTS[v12]= PY311=OFF PY312=ON RUN_DEPENDS= python-ansible:single:python_used DISTNAME= nb2an-0.9.11.dist-info GENERATED= yes [PY311].RUN_DEPENDS_ON= python-rich:single:v11 python-ruamel.yaml:single:v11 python-requests:single:v11 python-pyaml:single:v11 [PY311].USES_ON= python:v11,wheel [PY312].RUN_DEPENDS_ON= python-rich:single:v12 python-ruamel.yaml:single:v12 python-requests:single:v12 python-pyaml:single:v12 [PY312].USES_ON= python:v12,wheel [FILE:2998:descriptions/desc.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! [FILE:108:distinfo] 9e8343be643825189af66ea47c729a9b4978a9944a1d87493ac839e9e7b33fb7 17473 nb2an-0.9.11-py3-none-any.whl