NETBOX как dynamic inventory для Ansible — различия между версиями
Root (обсуждение | вклад) |
Root (обсуждение | вклад) |
||
| (не показана 1 промежуточная версия этого же участника) | |||
| Строка 1: | Строка 1: | ||
| + | Create and activate a Python 3 virtual environment: | ||
| + | python3 -m venv ./venv | ||
| + | source venv/bin/activate | ||
| + | |||
| + | |||
| + | Install Python Modules and Ansible | ||
| + | pip install pytz | ||
| + | pip install pynetbox | ||
| + | pip install ansible | ||
| + | |||
| + | |||
| + | Install the NetBox Ansible Collection. | ||
| + | |||
| + | Before using this collection, you need to install it with the Ansible Galaxy command-line tool | ||
| + | ansible-galaxy collection install netbox.netbox | ||
| + | |||
| + | |||
| + | Set environment variables for your NetBox API token and URL of your NetBox instance: | ||
| + | export NETBOX_API=<YOUR_NETBOX_URL> (note - must include http:// or https://) | ||
| + | export NETBOX_TOKEN=<YOUR_NETBOX_API_TOKEN> | ||
| + | |||
| + | |||
| + | Приводим конфиг примерно к такому виду | ||
--- | --- | ||
plugin: netbox.netbox.nb_inventory | plugin: netbox.netbox.nb_inventory | ||
| Строка 22: | Строка 45: | ||
| − | https://netboxlabs.com/docs/integrations/tool-integrations/netbox-ansible-collection/#use-case-1---netbox-as-a-dynamic-inventory-source-for-ansible | + | https://netboxlabs.com/docs/integrations/tool-integrations/netbox-ansible-collection/#use-case-1---netbox-as-a-dynamic-inventory-source-for-ansible<br> |
| − | https://docs.ansible.com/projects/ansible/latest/collections/netbox/netbox/nb_inventory_inventory.html | + | |
| − | https://habr.com/ru/companies/ruvds/articles/962710/ | + | https://docs.ansible.com/projects/ansible/latest/collections/netbox/netbox/nb_inventory_inventory.html<br> |
| + | |||
| + | https://habr.com/ru/companies/ruvds/articles/962710/<br> | ||
| + | |||
https://demo.netbox.dev/api/schema/swagger-ui/#/ | https://demo.netbox.dev/api/schema/swagger-ui/#/ | ||
Текущая версия на 01:17, 17 марта 2026
Create and activate a Python 3 virtual environment:
python3 -m venv ./venv source venv/bin/activate
Install Python Modules and Ansible
pip install pytz pip install pynetbox pip install ansible
Install the NetBox Ansible Collection.
Before using this collection, you need to install it with the Ansible Galaxy command-line tool
ansible-galaxy collection install netbox.netbox
Set environment variables for your NetBox API token and URL of your NetBox instance:
export NETBOX_API=<YOUR_NETBOX_URL> (note - must include http:// or https://) export NETBOX_TOKEN=<YOUR_NETBOX_API_TOKEN>
Приводим конфиг примерно к такому виду
--- plugin: netbox.netbox.nb_inventory api_endpoint: https://netbox.iwad.ru token: fc58b84c25bet54y6u356grf577ff297213ee validate_certs: false config_context: false group_names_raw: True group_by: - device_roles compose: nbx_role: role.name primary_ip_address: primary_ip.address query_filters: - status: 'active' - cf_device_class: server - tenant: org_iwad device_query_filters: - has_primary_ip: 'true' vm_query_filters: - has_primary_ip: 'true'