Building on previous work for subnet scanning with ansible, I've written a small playbook to identify IP conflicts within a remote network using ansible. The inventory for the playbook can be any host that has the arping
command, which includes any linux machine, or edgemax router. The beauty of the playbook is its simplicity and condensed output. Certainly this isn't an intended use for ansible, but being able to do this with ansible highlights its versatility.
---
- hosts: all
gather_facts: no
vars:
# net and ifc vars may be moved to inventory, or a prompt
net : 172.30.11.50/29
ifc : eth1
# lazy regex for MAC addresses
mrx : '[0-9a-fA-F:]{17}'
tasks:
- name: Check for IP conflict
command: arping -bc1 -I{{ ifc }} {{ net|ipaddr(item)|ipaddr('address') }}
become: true
register: r_arp
changed_when: r_arp.stdout is not regex("Received [01] rep")
failed_when: r_arp.stderr|default('')|length > 0
loop_control: { label: "{{ net|ipaddr(item)|ipaddr('address') }} - {{ r_arp.stdout|regex_findall(mrx) }}" }
with_sequence: end={{ net|ipaddr('size')|int -2 }}
See it in action: