ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
822 stars 1.52k forks source link

Nmap inventory plugin fails to run #7320

Open EnsuingRequiem opened 1 year ago

EnsuingRequiem commented 1 year ago

Summary

When trying to run nmap inventory plugin with basic configuration, it fails to parse. It appears when the code was changed from _options subscripting to get_option method, the brackets were not converted to parenthesis.

Issue Type

Bug Report

Component Name

nmap

Ansible Version

$ ansible --version
ansible [core 2.15.4]
  config file = /tachy/ansible/ansible.cfg
  configured module search path = ['/home/levi/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/levi/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] (/usr/bin/python3)
  jinja version = 3.0.3
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general
# /home/levi/.ansible/collections/ansible_collections
Collection        Version                                   ----------------- -------
community.general 7.4.0

# /usr/lib/python3/dist-packages/ansible_collections
Collection        Version
----------------- -------
community.general 7.4.0

Configuration

$ ansible-config dump --only-changed
CONFIG_FILE() = /tachy/ansible/ansible.cfg                                                                                   DEFAULT_PRIVATE_KEY_FILE(/tachy/ansible/ansible.cfg) = /tachy/ansible/id_rsa
INVENTORY_ENABLED(/tachy/ansible/ansible.cfg) = ['host_list', 'script', 'auto', 'yaml', 'ini', 'toml', 'nmap']

OS / Environment

Distributor ID: Ubuntu
Description:    Ubuntu 22.04.3 LTS
Release:        22.04
Codename:       jammy

Steps to Reproduce

plugin: community.general.nmap
address: 10.10.42.1

Expected Results

I expected the nmap inventory to run and return a list of hosts

Actual Results

[WARNING]:  * Failed to parse /tachy/ansible/inventory/nmap.yaml with auto plugin: 'method' object is not subscriptable
[WARNING]:  * Failed to parse /tachy/ansible/inventory/nmap.yaml with yaml plugin: Plugin configuration YAML file, not YAML
inventory
[WARNING]:  * Failed to parse /tachy/ansible/inventory/nmap.yaml with ini plugin: Invalid host pattern '---' supplied, '---'
is normally a sign this is a YAML file.
[WARNING]:  * Failed to parse /tachy/ansible/inventory/nmap.yaml with
ansible_collections.community.general.plugins.inventory.nmap plugin: 'method' object is not subscriptable
[WARNING]: Unable to parse /tachy/ansible/inventory/nmap.yaml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
{
    "_meta": {
        "hostvars": {}
    },
    "all": {
        "children": [
            "ungrouped"
        ]
    }
}

Code of Conduct

ansibullbot commented 1 year ago

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

EnsuingRequiem commented 1 year ago

Additionally, while looking at the dns_resolve option: https://github.com/ansible-collections/community.general/blob/7bf24eeb84bcd66b4bcdee832204cb4e2500be7f/plugins/inventory/nmap.py#L225-L226

I see there is an incorrect flag being used per nmap's help output:

Nmap 7.80 ( https://nmap.org )
Usage: nmap [Scan Type(s)] [Options] (target specification)
TARGET SPECIFICATION:
[...]
HOST DISCOVERY:
[..:]
  -n/-R: Never do DNS resolution/Always resolve [default: sometimes]

dns_resolve should append -n if false and -R if true

felixfontein commented 1 year ago

I created a PR to fix the get_option calls (#7323).

The -n should be fixed in a separate PR since it should be backported even further (get_option was only changed in stable-7).