# examples/dynamic_inventory/netbox_inventory.yml # This file configures the NetBox dynamic inventory plugin for Ansible. # # The NetBox dynamic inventory plugin allows Ansible to fetch inventory data directly from NetBox, # a popular DCIM (Data Center Infrastructure Management) tool. This plugin is part of the netbox.netbox # collection and enables you to dynamically generate Ansible inventory based on the devices and # virtual machines defined in NetBox. # # Prerequisites: # 1. Ensure NetBox is installed and running. # 2. Install the netbox.netbox collection using the following command: # ansible-galaxy collection install netbox.netbox # # Configuration: # - `plugin`: Specifies the NetBox inventory plugin to use. # - `api_endpoint`: The URL of the NetBox API endpoint. # - `validate_certs`: Whether to validate SSL certificates. Set to `False` if using self-signed certificates. # - `token`: Authentication token for NetBox. You can generate this token from the NetBox admin interface. # - `group_by`: Defines how to group the devices. In this example, devices are grouped by their roles. # - `query_filters`: Optional filters to limit the devices fetched from NetBox. # - `compose`: Allows you to set host variables using NetBox data. plugin: netbox.netbox.nb_inventory # Specify the NetBox inventory plugin api_endpoint: http://localhost:8000 # NetBox API endpoint validate_certs: True # Validate SSL certificates # Optional: Use a token for authentication token: type: Bearer value: your_netbox_token # Group devices by their roles group_by: - device_roles # Apply query filters to limit the devices fetched from NetBox query_filters: - role: network-edge-router # Example of using the compose option to set host variables compose: foo: last_updated bar: display_name nested_variable: rack.display_name # Example command to test the inventory plugin: # ansible-inventory -v --list -i netbox_inventory.yml # Example playbook using the dynamic inventory: # ansible-playbook -i netbox_inventory.yml your_playbook.yml # Example playbook content: # your_playbook.yml # --- # - name: Playbook using NetBox Inventory Plugin for Ansible # hosts: device_roles_access_switch # tasks: # - name: Example task # debug: # msg: "Running task on {{ inventory_hostname }}" # References: # - NetBox Inventory Source - Ansible Documentation: https://docs.ansible.com/ansible/latest/collections/netbox/netbox/nb_inventory_inventory.html # - Using NetBox as a Dynamic Inventory in Red Hat Ansible - NetBox Labs: https://netboxlabs.com/blog/how-to-use-netbox-as-a-dynamic-inventory-source-for-the-red-hat-ansible-automation-platform/ # - Ansible Dynamic Inventory Using Plugins - Network to Code: https://blog.networktocode.com/post/Ansible-Dynamic-Inventory-using-Plugins/