0% found this document useful (0 votes)
7 views

Discovery IPv4 Address with nmap and Ansible

Uploaded by

gandalf56
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Discovery IPv4 Address with nmap and Ansible

Uploaded by

gandalf56
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Download PNETLab Platform

PNETLAB Store
PNETLab.com

Discovery IPv4 Address with nmap and Ansible

1. Lab Topology

https://user.pnetlab.com/store/labs/detail?id=16011204105834

2. Requirements

Ansible.

Linux commands.

CCNA.

3. Lab Objective

This lab will show you how to create playbook discovery ip address of devices.

4.Lab setup

1
Download PNETLab Platform
PNETLAB Store
PNETLab.com

This lab configured ip address, just forcus with Ansible playbook.

You need install Ansible platform with this guide:

This lab use Ansible platform version 2.9.6, you can get it on devices mode in
PNETLab GUI:

You should reading guide before download and use this platforms:

https://user.pnetlab.com/store/devices/guide?id=4

IP address on eth1 of Ansible workstation is configured 192.168.1.1/24

Password login Ansible Worstation: admin/admin

5.Lab Guide

This lab has 3 steps:

• Step 1: Install NMAP.


o apt install nmap -y

2
Download PNETLab Platform
PNETLAB Store
PNETLab.com

• Step 2: Create playbook discovery and collect ip address of devices that Ansible
workstation see.
o cd /etc/ansible/
o touch run.yml
o Edit playbook
o vim run.yml
o Playbook include below tasks:
▪ Collect data with nmap scan ip:

3
Download PNETLab Platform
PNETLAB Store
PNETLab.com

▪ For this lab, I scan address with net: 192.168.1.0/24

▪ Filter data:

▪ Check file that you will save data:

▪ Add ip address in file:

o Save them and run playbook


o Ansible-playbook run.yml
• Step 3: Checking.

4
Download PNETLab Platform
PNETLAB Store
PNETLab.com

o This’s result:

You can explain this lab on topology configured routing protocols or with other devices.
Finish this lab!

6. Solution:

Playbook:

---
- name: Discovery Host...
hosts: localhost
connection: local
gather_facts: false

tasks:
- name: Collecting data…..
shell: "nmap -sn -oG - {{ scan_net }}"
vars:
scan_net: 192.168.1.0/24
register: data_input

- set_fact:

5
Download PNETLab Platform
PNETLAB Store
PNETLab.com

hostname: "{{ data_input.stdout | regex_findall('\\b(?:[0-9]{1,3}\\.){2}[0-9]{1,3}\\.[1-


9]{1,3}\\b') }}"
vars:
filter: '(?<=Host: ).*'

- name: Collect successful!!! Checking save file.....


find:
path: "/etc/ansible/hostname-collect"
register: check_file

- name: File not existed! Creating file in dir /etc/ansible/.....


file:
path: /etc/ansible/hostname-collect
state: touch
mode: 0775
when: check_file.matched == 0

- name: Complete Collection :D Checking file hostname-collect


lineinfile:
path: "/etc/ansible/hostname-collect"
line: "{{ item }}"
mode: 0775
with_items: "{{ hostname }}"

You might also like