Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nmap inventory plugin: Add sudo nmap #4506

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/4506-sudo-in-nmap-inv-plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- nmap inventory plugin - add ``sudo`` option in plugin in order to execute ``sudo nmap`` so that ``nmap`` runs with elevated privileges (https://github.com/ansible-collections/community.general/pull/4506).
15 changes: 15 additions & 0 deletions plugins/inventory/nmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
description: token that ensures this is a source file for the 'nmap' plugin.
required: True
choices: ['nmap', 'community.general.nmap']
sudo:
description: Set to C(true) to execute a C(sudo nmap) plugin scan.
version_added: 4.8.0
type: boolean
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
address:
description: Network IP or range of IPs to scan, you can use a simple range (10.2.2.15-25) or CIDR notation.
required: True
Expand Down Expand Up @@ -49,6 +53,13 @@
plugin: community.general.nmap
strict: False
address: 192.168.0.0/24


# a sudo nmap scan to fully use nmap scan power.
plugin: community.general.nmap
sudo: true
strict: False
address: 192.168.0.0/24
'''

import os
Expand Down Expand Up @@ -135,6 +146,10 @@ def parse(self, inventory, loader, path, cache=True):
if not user_cache_setting or cache_needs_update:
# setup command
cmd = [self._nmap]

if self._options['sudo']:
cmd.insert(0, 'sudo')

if not self._options['ports']:
cmd.append('-sP')

Expand Down