可以按照以下步骤使用 community.general.nmap
插件:
nmap
和 python-nmap
。ansible.cfg
文件中添加以下内容:[inventory]
enable_plugins = host_list, virtualbox, yaml, constructed, community.general.nmap
community.general.nmap
插件。以下是示例代码:- name: Use nmap plugin to scan hosts
hosts: all
gather_facts: no
tasks:
- name: Run nmap scan
nmap:
hosts: 192.168.1.0/24
ports: 22,80
register: nmap_out
- name: Print nmap scan output
debug: var=nmap_out
本示例使用 nmap
插件扫描 192.168.1.0/24
的网络,打印出开放的 22
和 80
端口。可以根据需要修改任务和参数,使用该插件进行主机扫描。