Ansible Nmap

Hello all

I have network 172.130.23.0/20 with a lot of router
I tried to make inventory file for ansible.

https://docs.ansible.com/ansible/latest/plugins/inventory/nmap.html

How can I use ansible nmap for scanning my network to make inventory file?

I google it, I didn’t find any

Thank you

Mayang

The nmap inventory plugin does not create a file, it uses nmap every
time to generate the inventory in memory for ansible.

You can however use `ansible-inventory --list --yaml -i test.nmap.yml

inventory.yml` to generate a static inventory

it works with any plugin type, so you can do the same with a cloud
inventory and others.

contents of test.nmap.yml

    plugin: nmap
    strict: False
    address: 172.130.23..0/20

Hello Brain,

Sorry for late replay
I tried and got this error

ansible-inventory --list --yaml -i test.nmap.yml > inventory.yml
[WARNING]: * Failed to parse /Jaks/test.nmap.yml with yaml plugin: Plugin configuration YAML file,
not YAML inventory
[WARNING]: * Failed to parse /Jaks/test.nmap.yml with constructed plugin: Incorrect plugin name in
file: nmap
[WARNING]: Unable to parse /Jaks/test.nmap.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available

and when I tried with -vvvv

ansible-inventory --list --yaml -i test.nmap.yml -vvvv
ansible-inventory 2.9.12
config file = /etc/ansible/ansible.cfg
configured module search path = [‘/home/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]
ansible python module location = /opt/anaconda3/lib/python3.8/site-packages/ansible
executable location = /opt/anaconda3/bin/ansible-inventory
python version = 3.8.3 (default, Jul 2 2020, 16:21:59) [GCC 7.3.0]
Using /etc/ansible/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /Jaks/test.nmap.yml as it did not pass its verify_file() method
virtualbox declined parsing /Jaks/test.nmap.yml as it did not pass its verify_file() method
[WARNING]: * Failed to parse /Jaks/test.nmap.yml with yaml plugin: Plugin configuration YAML file,
not YAML inventory
File “/opt/anaconda3/lib/python3.8/site-packages/ansible/inventory/manager.py”, line 280, in parse_source
plugin.parse(self._inventory, self._loader, source, cache=cache)
File “/opt/anaconda3/lib/python3.8/site-packages/ansible/plugins/inventory/yaml.py”, line 112, in parse
raise AnsibleParserError(‘Plugin configuration YAML file, not YAML inventory’)
[WARNING]: * Failed to parse /Jaks/test.nmap.yml with constructed plugin: Incorrect plugin name in
file: nmap
File “/opt/anaconda3/lib/python3.8/site-packages/ansible/inventory/manager.py”, line 280, in parse_source
plugin.parse(self._inventory, self._loader, source, cache=cache)
File “/opt/anaconda3/lib/python3.8/site-packages/ansible/plugins/inventory/constructed.py”, line 109, in parse
self._read_config_data(path)
File “/opt/anaconda3/lib/python3.8/site-packages/ansible/plugins/inventory/init.py”, line 224, in _read_config_data
raise AnsibleParserError(“Incorrect plugin name in file: %s” % config.get(‘plugin’, ‘none found’))
[WARNING]: Unable to parse /Jaks/test.nmap.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
all:
children:
ungrouped: {}

how to fix this?

I tried edit /etc/ansible/ansible.cfg and add ini and auto in enable_plugins

Hello all

Sorry I just curious, is this normal result for plugin nmap?

ansible-inventory --list --yaml -i test.nmap.yml -vvvv
ansible-inventory 2.9.12
config file = /etc/ansible/ansible.cfg
configured module search path = [‘/home/oss/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]
ansible python module location = /opt/anaconda3/lib/python3.8/site-packages/ansible
executable location = /opt/anaconda3/bin/ansible-inventory
python version = 3.8.3 (default, Jul 2 2020, 16:21:59) [GCC 7.3.0]
Using /etc/ansible/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /Jaks/test.nmap.yml as it did not pass its verify_file() method
virtualbox declined parsing /Jaks/test.nmap.yml as it did not pass its verify_file() method
Parsed /Jaks/test.nmap.yml inventory source with auto plugin
all:
children:
ungrouped: {}