Плагин инвентаризации Anisble Nmap

#ansible #nmap #inventory

#ансибль #nmap #инвентаризация

Вопрос:

Привет, я пытаюсь создать динамическую инвентаризацию, которая сканирует сеть в поисках хостов для добавления, на данный момент я немного застрял, и я не знаю, что мне делать, чтобы устранить неполадки. я использовал этот каталог в основном для настройки https://www.ansible.com/blog/using-an-inventory-plugin-from-a-collection-in-ansible-tower

Я продолжаю получать эту ошибку в ansbile

     1.646 INFO     Updating inventory 10: PXE clients
1.657 DEBUG    Using base command: python /usr/bin/ansible-inventory -i /tmp/awx_744__2xl1jk8/project --playbook-dir /tmp/awx_744__2xl1jk8/project -vvvvv
1.657 INFO     Reading Ansible inventory source: /tmp/awx_744__2xl1jk8/project
1.658 INFO     Using VIRTUAL_ENV: /var/lib/awx/venv/ansible
1.658 INFO     Using PATH: /var/lib/awx/venv/ansible/bin:/var/lib/awx/venv/awx/bin:/usr/pgsql-10/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
1.658 INFO     Using PYTHONPATH: /var/lib/awx/venv/ansible/lib/python3.6/site-packages:
1.970 ERROR    ansible-inventory 2.9.14
1.970 ERROR      config file = /etc/ansible/ansible.cfg
1.970 ERROR      configured module search path = ['/var/lib/awx/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
1.970 ERROR      ansible python module location = /usr/lib/python3.6/site-packages/ansible
1.970 ERROR      executable location = /usr/bin/ansible-inventory
1.970 ERROR      python version = 3.6.8 (default, Apr 16 2020, 01:36:27) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]
1.970 ERROR    Using /etc/ansible/ansible.cfg as config file
1.970 ERROR    setting up inventory plugins
1.970 ERROR    host_list declined parsing /tmp/awx_744__2xl1jk8/project/Nmap.yml as it did not pass its verify_file() method
1.970 ERROR    script declined parsing /tmp/awx_744__2xl1jk8/project/Nmap.yml as it did not pass its verify_file() method
1.970 ERROR    toml declined parsing /tmp/awx_744__2xl1jk8/project/Nmap.yml as it did not pass its verify_file() method
1.970 ERROR    [WARNING]:  * Failed to parse /tmp/awx_744__2xl1jk8/project/Nmap.yml with auto
1.970 ERROR    plugin: failed to parse /tmp/awx_744__2xl1jk8/project/Nmap.yml: expected str,
1.970 ERROR    bytes or os.PathLike object, not NoneType
1.970 ERROR      File "/usr/lib/python3.6/site-packages/ansible/inventory/manager.py", line 280, in parse_source
1.970 ERROR        plugin.parse(self._inventory, self._loader, source, cache=cache)
1.970 ERROR      File "/usr/lib/python3.6/site-packages/ansible/plugins/inventory/auto.py", line 58, in parse
1.970 ERROR        plugin.parse(inventory, loader, path, cache=cache)
1.970 ERROR      File "/var/lib/awx/.ansible/collections/ansible_collections/community/general/plugins/inventory/nmap.py", line 168, in parse
1.970 ERROR        raise AnsibleParserError("failed to parse %s: %s " % (to_native(path), to_native(e)))
1.970 ERROR    [WARNING]:  * Failed to parse /tmp/awx_744__2xl1jk8/project/Nmap.yml with yaml
1.970 ERROR    plugin: Plugin configuration YAML file, not YAML inventory
1.970 ERROR      File "/usr/lib/python3.6/site-packages/ansible/inventory/manager.py", line 280, in parse_source
1.970 ERROR        plugin.parse(self._inventory, self._loader, source, cache=cache)
1.970 ERROR      File "/usr/lib/python3.6/site-packages/ansible/plugins/inventory/yaml.py", line 112, in parse
1.970 ERROR        raise AnsibleParserError('Plugin configuration YAML file, not YAML inventory')
1.970 ERROR    [WARNING]:  * Failed to parse /tmp/awx_744__2xl1jk8/project/Nmap.yml with ini
1.970 ERROR    plugin: Invalid host pattern '---' supplied, '---' is normally a sign this is a
1.970 ERROR    YAML file.
1.970 ERROR      File "/usr/lib/python3.6/site-packages/ansible/inventory/manager.py", line 280, in parse_source
1.970 ERROR        plugin.parse(self._inventory, self._loader, source, cache=cache)
1.970 ERROR      File "/usr/lib/python3.6/site-packages/ansible/plugins/inventory/ini.py", line 138, in parse
1.970 ERROR        raise AnsibleParserError(e)
1.970 ERROR    [WARNING]: Unable to parse /tmp/awx_744__2xl1jk8/project/Nmap.yml as an
1.970 ERROR    inventory source
1.970 ERROR    setting up inventory plugins
1.970 ERROR    host_list declined parsing /tmp/awx_744__2xl1jk8/project/collections/requirments.yml as it did not pass its verify_file() method
1.970 ERROR    script declined parsing /tmp/awx_744__2xl1jk8/project/collections/requirments.yml as it did not pass its verify_file() method
1.971 ERROR    [WARNING]: Skipping 'collections' as this is not a valid group definition
1.971 ERROR    Parsed /tmp/awx_744__2xl1jk8/project/collections/requirments.yml inventory source with yaml plugin
1.971 DEBUG    Finished loading from source: /tmp/awx_744__2xl1jk8/project
1.971 INFO     Processing JSON output...
1.971 DEBUG    Loaded group: all
1.971 INFO     Loaded 0 groups, 0 hosts
1.980 DEBUG    Inventory variables unmodified
 

Я использую этот плагин: https://docs.ansible.com/ansible/latest/collections/community/general/nmap_inventory.html

и мой файл плагина маленький:

     ---
   plugin: community.general.nmap
   strict: False
   ipv4: True
   address: 39.0.0.0/24
 

Настройка моего источника инвентаризации Ansible

Ответ №1:

В верхней строке перед --- удалением есть пробел, который устранит эту ошибку. Имейте в виду, что плагин инвентаризации nmap требует, чтобы nmap cli был установлен на управляющем узле. Если вы выполняете это в среде выполнения по умолчанию в tower, это приведет к сбою. Вам нужно будет добавить еще один с пользовательской спецификацией изображения / модуля, которая включает nmap-cli.