This commit is contained in:
Kevin Heyer 2025-04-22 12:38:55 +02:00
commit a621c3148d
10 changed files with 108 additions and 0 deletions

0
README.md Normal file
View file

View file

View file

@ -0,0 +1,65 @@
# 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/

View file

@ -0,0 +1,12 @@
# examples/group_vars/webservers.yml
# This file contains variables that apply to all hosts in the 'webservers' group.
---
# User to connect as
ansible_user: webadmin
# Port for HTTP service
http_port: 80
# Maximum number of clients
max_clients: 200

View file

@ -0,0 +1,12 @@
# examples/host_vars/web1.example.com.yml
# This file contains variables specific to the 'web1.example.com' host.
---
# IP address of the host
ansible_host: 192.168.1.10
# User to connect as
ansible_user: webadmin
# Port for HTTP service
http_port: 8080

19
examples/inventory.yml Normal file
View file

@ -0,0 +1,19 @@
# examples/inventory.yml
# This is an example Ansible inventory file. It defines a set of hosts and groups them into categories.
all:
# List of all hosts
hosts:
web1.example.com:
web2.example.com:
db1.example.com:
children:
# Group of web servers
webservers:
hosts:
web1.example.com:
web2.example.com:
# Group of database servers
dbservers:
hosts:
db1.example.com:

0
group_vars/.gitkeep Normal file
View file

0
host_vars/.gitkeep Normal file
View file

0
production.yml Normal file
View file

0
testing.yml Normal file
View file