I was creating a playbook to scan hosts and add them to an inventory. To start, I made my ansible playbook to install
nmap
on ubuntu withsnap
if it wasn't already installed.
The scan worked wonderfully, until I wanted to output to a file.
$ nmap -sn 10.10.10.0/24 -oX scan.xml
Failed to open XML output file scan.xml for writing
QUITTING!
I tried several different options, including a short dive into the nmap source code
/* Open a log descriptor of the type given to the filename given. If
append is true, the file will be appended instead of clobbered if
it already exists. If the file does not exist, it will be created */
int log_open(int logt, bool append, char *filename) {
int i = 0;
if (logt <= 0 || logt > LOG_FILE_MASK)
return -1;
while ((logt & 1) == 0) {
i++;
logt >>= 1;
}
if (o.logfd[i])
fatal("Only one %s output filename allowed", logtypes[i]);
if (*filename == '-' && *(filename + 1) == '\0') {
o.logfd[i] = stdout;
o.nmap_stdout = fopen(DEVNULL, "w");
if (!o.nmap_stdout)
fatal("Could not assign %s to stdout for writing", DEVNULL);
} else {
if (append)
o.logfd[i] = fopen(filename, "a");
else
o.logfd[i] = fopen(filename, "w");
if (!o.logfd[i])
fatal("Failed to open %s output file %s for writing", logtypes[i],
filename);
}
return 1;
}
Then I skipped over to the ubuntu forums and found out that nmap
has issues when installed with snap
. The post suggested removing and installing with apt
...
$ sudo snap remove nmap
$ sudo apt install nmap
$ nmap -sn 10.10.10.0/24 -oX scan.xml
bash: /snap/bin/nmap: No such file or directory
GAAAAAAHHHH!!! dying inside
A couple more searches and I found how to get the system to let go of the cached links
hash -r
Ok, let's try again...
$ nmap -sn 10.10.10.0/24 -oX scan.xml
Starting Nmap 7.80...
YAY4THAT!