Search code examples
ansiblenmapinventory

Anisble Nmap inventory plugin


Hey I am trying to make a dynamic Inventory that scans the network looking for hosts to add, At the moment i am kinda stuck And i don't know what i should do to trouble shoot i used this turtorial mainly to set this up https://www.ansible.com/blog/using-an-inventory-plugin-from-a-collection-in-ansible-tower

I keep getting this error, in 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

I am using this plugin: https://docs.ansible.com/ansible/latest/collections/community/general/nmap_inventory.html

and my plugin file is small:

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

My Ansible inventory Source setup


Solution

  • There is a space on the top line before --- removing that will get past this error. Keep in mind the nmap inventory plugin requires the nmap cli be installed on the control node. If you are executing this on the default execution environment in tower it will fail. You'll need to add another with a custom image/pod spec that includes the nmap-cli.