NETBOX как dynamic inventory для Ansible — различия между версиями
Root (обсуждение | вклад) |
Root (обсуждение | вклад) |
||
| Строка 32: | Строка 32: | ||
gather_timeout: 10<br> | gather_timeout: 10<br> | ||
| − | [ssh_connection] | + | [ssh_connection]<br> |
scp_if_ssh = True<br> | scp_if_ssh = True<br> | ||
delay=10<br> | delay=10<br> | ||
| Строка 40: | Строка 40: | ||
</spoiler> | </spoiler> | ||
| + | <spoiler> | ||
| + | [[source]] | ||
| + | url = "https://pypi.org/simple" | ||
| + | verify_ssl = true | ||
| + | name = "pypi" | ||
| + | |||
| + | [packages] | ||
| + | requests = "==2.26.0" | ||
| + | proxmoxer = "==2.0.1" | ||
| + | ansible = "==9.7.0" | ||
| + | ansible-lint = "==6.14.4" | ||
| + | hvac = "==0.11.2" | ||
| + | dnspython = "==2.3.0" | ||
| + | pyvcloud = "==23.0.4" | ||
| + | lxml = "==4.9.2" | ||
| + | pynetbox = "==6.6.2" | ||
| + | zabbix-api = "==0.5.5" | ||
| + | pure-sasl = "==0.5.1" | ||
| + | netaddr = "==0.8.0" | ||
| + | pytz = "==2023.3" | ||
| + | "molecule[ansible]" = "==4.0.1" | ||
| + | molecule-proxmox = "==0.7.0" | ||
| + | ansible-compat = "==25.1.4" | ||
| + | "requests[socks]"="==2.26.0" | ||
| + | pywinrm = "==0.5.0" | ||
| + | |||
| + | [dev-packages] | ||
| + | |||
| + | [requires] | ||
| + | python_version = "3.11" | ||
| + | </spoiler> | ||
Создадим директории и положим конфиги и прочее | Создадим директории и положим конфиги и прочее | ||
/inventories | /inventories | ||
Версия 17:43, 18 марта 2026
Для начала подготовим виртуалочку для управления инфрой через ansible. Использовать будем Debian 12
Ставим python3.11 (т.к. он будет в зависимостях в нашем Pipfile) и pip
apt install python3.11-full apt install pip
Устанавливаем pipenv
pip install pipenv --break-system-packages
Подготавливаем ansible.cfg и Pipfile с зависимостями
Spoiler
Создадим директории и положим конфиги и прочее
/inventories /iwad /group_vars all.yaml netbox-inventory.yaml /playbooks /base ansible.cfg base.yaml Pipfile /roles /base
Клонируем репу с базовой ролью
Создаём виртуальное окружение
cd /root/ansible/playbooks/base pipenv install pipenv shell
Приводим /inventories/iwad/netbox-inventory.yaml примерно к такому виду
--- plugin: netbox.netbox.nb_inventory api_endpoint: https://netbox.iwad.ru token: fc58b84c25grbc5506627a8c32r32a397213ee 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'
проверяем что инвентарь парсится(конечно же в netbox уже должны быть внесены устройства)
ansible-inventory -i ../../inventories/iwad --graph @all: |--@ungrouped: |--@proxmox: | |--pve36.iwad.ru | |--pve37.iwad.ru | |--pve38.iwad.ru | |--pve42.iwad.ru
или
ansible-inventory -i ../../inventories/iwad --list
кладём id_rsa поьзователю ansible(не умно, признаю) и пробуем катать базовую роль
РАБОТАЕМ!!!