{"id":19565373,"url":"https://github.com/nchekwa/netbox-awx-inventory-script","last_synced_at":"2026-05-03T11:32:34.803Z","repository":{"id":157757283,"uuid":"283351367","full_name":"nchekwa/netbox-awx-inventory-script","owner":"nchekwa","description":"Create inventory in Ansible Tower (AWX) based on default netbox Ansbile plugin","archived":false,"fork":false,"pushed_at":"2020-07-31T04:06:36.000Z","size":74,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-26T09:30:12.753Z","etag":null,"topics":["ansible","ansible-galaxy","ansible-tower","awx","bash","netbox"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nchekwa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-28T23:38:35.000Z","updated_at":"2021-05-25T17:50:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"8a65496c-e223-4d70-9c2b-878c085423ce","html_url":"https://github.com/nchekwa/netbox-awx-inventory-script","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nchekwa/netbox-awx-inventory-script","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nchekwa%2Fnetbox-awx-inventory-script","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nchekwa%2Fnetbox-awx-inventory-script/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nchekwa%2Fnetbox-awx-inventory-script/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nchekwa%2Fnetbox-awx-inventory-script/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nchekwa","download_url":"https://codeload.github.com/nchekwa/netbox-awx-inventory-script/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nchekwa%2Fnetbox-awx-inventory-script/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32567253,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T06:36:36.687Z","status":"ssl_error","status_checked_at":"2026-05-03T06:36:09.306Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","ansible-galaxy","ansible-tower","awx","bash","netbox"],"created_at":"2024-11-11T05:26:29.253Z","updated_at":"2026-05-03T11:32:34.785Z","avatar_url":"https://github.com/nchekwa.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Create inventory in Ansible Tower (AWX) based on default netbox Ansbile plugin\n\n\n Before you start:\u003cbr\u003e\n Please note that all this was done on **OLD** legacy netbox ansible plugin.\u003cbr\u003e\n Right now there is more advanced library to manage netbox available under this [Link](https://github.com/netbox-community/ansible_modules)\n\n\n1) Put script ie. in /opt/scripts/pb.netbox_inventory.yml \n\n```yaml\nplugin: netbox\napi_endpoint: http://192.168.254.90\nvalidate_certs: False\nconfig_context: True\ntoken: 678bcbfccbbcb6a59069438vv9b5d0f9e4a3081a\ngroup_by:\n  - device_roles\nquery_filters:\n  - tag: ansible\ncompose:\n  ansible_network_os: platform.slug\n\n```\n\nMore details about [NetBox inventory source](https://docs.ansible.com/ansible/latest/plugins/inventory/netbox.html \"Link\")\n\n2) In AWX 'Inventory Scripts' create new script which will generate JSON output:\n```bash\n#!/usr/bin/env bash\nansible-inventory -v --list -i /opt/scripts/netbox_inventory.yml\n```\n![Screenshot](awx_inventory.png)\n\n\n# Output example when we run playbook from bash level:\n```bash\nansible-inventory -v --list -i /opt/scripts/netbox_inventory.yml\n```\n\n```json\nUsing /etc/ansible/ansible.cfg as config file\nFetching: http://192.168.254.90/api/dcim/sites/?limit=0\nFetching: http://192.168.254.90/api/dcim/regions/?limit=0\nFetching: http://192.168.254.90/api/tenancy/tenants/?limit=0\nFetching: http://192.168.254.90/api/dcim/racks/?limit=0\nFetching: http://192.168.254.90/api/dcim/device-roles/?limit=0\nFetching: http://192.168.254.90/api/dcim/platforms/?limit=0\nFetching: http://192.168.254.90/api/dcim/device-types/?limit=0\nFetching: http://192.168.254.90/api/dcim/manufacturers/?limit=0\nFetching: http://192.168.254.90/api/dcim/devices/?limit=0\nFetching: http://192.168.254.90/api/virtualization/virtual-machines/?limit=0\n{\n    \"_meta\": {\n        \"hostvars\": {\n            \"Leaf-30\": {\n                \"ansible_network_os\": \"junos\",\n                \"config_context\": [\n                    {}\n                ],\n                \"device_roles\": [\n                    \"leaf_switch\"\n                ],\n                \"device_types\": [\n                    \"vqfx-10000\"\n                ],\n                \"manufacturers\": [\n                    \"Juniper\"\n                ],\n                \"platforms\": [\n                    \"junos\"\n                ],\n                \"sites\": [\n                    \"Warsaw DC1\"\n                ]\n            },\n            \"Leaf-31\": {\n                \"ansible_network_os\": \"junos\",\n                \"config_context\": [\n                    {}\n                ],\n                \"device_roles\": [\n                    \"leaf_switch\"\n                ],\n                \"device_types\": [\n                    \"vqfx-10000\"\n                ],\n                \"manufacturers\": [\n                    \"Juniper\"\n                ],\n                \"platforms\": [\n                    \"junos\"\n                ],\n                \"sites\": [\n                    \"Warsaw DC1\"\n                ]\n            },\n            \"Leaf-32\": {\n                \"ansible_network_os\": \"junos\",\n                \"config_context\": [\n                    {}\n                ],\n                \"device_roles\": [\n                    \"leaf_switch\"\n                ],\n                \"device_types\": [\n                    \"vqfx-10000\"\n                ],\n                \"manufacturers\": [\n                    \"Juniper\"\n                ],\n                \"platforms\": [\n                    \"junos\"\n                ],\n                \"sites\": [\n                    \"Warsaw DC1\"\n                ]\n            },\n            \"Leaf-33\": {\n                \"ansible_network_os\": \"junos\",\n                \"config_context\": [\n                    {}\n                ],\n                \"device_roles\": [\n                    \"leaf_switch\"\n                ],\n                \"device_types\": [\n                    \"vqfx-10000\"\n                ],\n                \"manufacturers\": [\n                    \"Juniper\"\n                ],\n                \"platforms\": [\n                    \"junos\"\n                ],\n                \"sites\": [\n                    \"Warsaw DC1\"\n                ]\n            },\n            \"Spine-20\": {\n                \"ansible_host\": \"10.240.40.20\",\n                \"ansible_network_os\": \"junos\",\n                \"config_context\": [\n                    {\n                        \"ansible_password\": \"Juniper\",\n                        \"ansible_user\": \"root\"\n                    }\n                ],\n                \"device_roles\": [\n                    \"spine_switch\"\n                ],\n                \"device_types\": [\n                    \"vqfx-10000\"\n                ],\n                \"manufacturers\": [\n                    \"Juniper\"\n                ],\n                \"platforms\": [\n                    \"junos\"\n                ],\n                \"primary_ip4\": \"10.240.40.20\",\n                \"sites\": [\n                    \"Warsaw DC1\"\n                ],\n                \"tags\": [\n                    \"ERB\"\n                ]\n            },\n            \"Spine-21\": {\n                \"ansible_host\": \"10.240.40.21\",\n                \"ansible_network_os\": \"junos\",\n                \"config_context\": [\n                    {}\n                ],\n                \"device_roles\": [\n                    \"spine_switch\"\n                ],\n                \"device_types\": [\n                    \"vqfx-10000\"\n                ],\n                \"manufacturers\": [\n                    \"Juniper\"\n                ],\n                \"platforms\": [\n                    \"junos\"\n                ],\n                \"primary_ip4\": \"10.240.40.21\",\n                \"sites\": [\n                    \"Warsaw DC1\"\n                ]\n            }\n        }\n    },\n    \"all\": {\n        \"children\": [\n            \"device_roles_leaf_switch\",\n            \"device_roles_spine_switch\",\n            \"ungrouped\"\n        ]\n    },\n    \"device_roles_leaf_switch\": {\n        \"hosts\": [\n            \"Leaf-30\",\n            \"Leaf-31\",\n            \"Leaf-32\",\n            \"Leaf-33\"\n        ]\n    },\n    \"device_roles_spine_switch\": {\n        \"hosts\": [\n            \"Spine-20\",\n            \"Spine-21\"\n        ]\n    }\n}\n\n```\n\n\n# PATCH: inventory_flat.py\n![Screenshot](awx_inventory_flat.png)\n\n### Before:\n```json\n \"Spine-20\": {\n                \"ansible_host\": \"10.240.40.20\",\n                \"ansible_network_os\": \"junos\",\n                \"config_context\": [\n                    {\n                        \"ansible_password\": \"Juniper\",\n                        \"ansible_user\": \"root\"\n                    }\n                ],\n                \"device_roles\": [\n                    \"spine_switch\"\n                ],\n                \"device_types\": [\n                    \"vqfx-10000\"\n                ],\n                \"manufacturers\": [\n                    \"Juniper\"\n                ],\n                \"platforms\": [\n                    \"junos\"\n                ],\n                \"primary_ip4\": \"10.240.40.20\",\n                \"sites\": [\n                    \"Warsaw DC1\"\n                ],\n                \"tags\": [\n                    \"ERB\"\n                ]\n```\n\n### With patch\n```json\n \"Spine-20\": {\n                \"ansible_host\": \"10.240.40.20\",\n                \"ansible_password\": \"Juniper\",\n                \"ansible_user\": \"root\",                       \u003c----------- !!!\n                \"ansible_network_os\": \"junos\",                \u003c----------- !!!\n                \"device_roles\": [\n                    \"spine_switch\"\n                ],\n                \"device_types\": [\n                    \"vqfx-10000\"\n                ],\n                \"manufacturers\": [\n                    \"Juniper\"\n                ],\n                \"platforms\": [\n                    \"junos\"\n                ],\n                \"primary_ip4\": \"10.240.40.20\",\n                \"sites\": [\n                    \"Warsaw DC1\"\n                ],\n                \"tags\": [\n                    \"ERB\"\n                ]\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnchekwa%2Fnetbox-awx-inventory-script","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnchekwa%2Fnetbox-awx-inventory-script","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnchekwa%2Fnetbox-awx-inventory-script/lists"}