From a621c3148dfc399a21a3d974e3589d143df698cd Mon Sep 17 00:00:00 2001 From: Kevin Heyer Date: Tue, 22 Apr 2025 12:38:55 +0200 Subject: [PATCH] Init --- README.md | 0 dynamic_inventory/.gitkeep | 0 examples/dynamic_inventory.yml | 65 +++++++++++++++++++++++++ examples/group_vars/webservers.yml | 12 +++++ examples/host_vars/web1.example.com.yml | 12 +++++ examples/inventory.yml | 19 ++++++++ group_vars/.gitkeep | 0 host_vars/.gitkeep | 0 production.yml | 0 testing.yml | 0 10 files changed, 108 insertions(+) create mode 100644 README.md create mode 100644 dynamic_inventory/.gitkeep create mode 100644 examples/dynamic_inventory.yml create mode 100644 examples/group_vars/webservers.yml create mode 100644 examples/host_vars/web1.example.com.yml create mode 100644 examples/inventory.yml create mode 100644 group_vars/.gitkeep create mode 100644 host_vars/.gitkeep create mode 100644 production.yml create mode 100644 testing.yml diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/dynamic_inventory/.gitkeep b/dynamic_inventory/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/examples/dynamic_inventory.yml b/examples/dynamic_inventory.yml new file mode 100644 index 0000000..19028cf --- /dev/null +++ b/examples/dynamic_inventory.yml @@ -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/ diff --git a/examples/group_vars/webservers.yml b/examples/group_vars/webservers.yml new file mode 100644 index 0000000..552e778 --- /dev/null +++ b/examples/group_vars/webservers.yml @@ -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 diff --git a/examples/host_vars/web1.example.com.yml b/examples/host_vars/web1.example.com.yml new file mode 100644 index 0000000..3606c8e --- /dev/null +++ b/examples/host_vars/web1.example.com.yml @@ -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 diff --git a/examples/inventory.yml b/examples/inventory.yml new file mode 100644 index 0000000..3a5f2bd --- /dev/null +++ b/examples/inventory.yml @@ -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: diff --git a/group_vars/.gitkeep b/group_vars/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/host_vars/.gitkeep b/host_vars/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/production.yml b/production.yml new file mode 100644 index 0000000..e69de29 diff --git a/testing.yml b/testing.yml new file mode 100644 index 0000000..e69de29