ryandaniels.connectivity_test
ansible-role-connectivity-test
This role uses nc
(netcat) to check for network problems to a given IP address and port (using TCP or UDP). It automatically selects the source IP based on the destination IP from the available network routes.
By default, it uses the TCP protocol. If you need to test with UDP, set protocol: udp
.
Supported Distributions
- Ubuntu 18.04 / 16.04
- CentOS / RHEL: 7.x, 6.5, 5.9
Requirements
The following system commands are needed:
- nc (netcat) - will be installed if not already present
- ip
- awk
Default Configuration
- Debug mode
debug_enabled_default: false
- Time to wait before timing out
connectivity_test_wait_default: 5
- For using UDP if specified in configuration
connectivity_test_udp_command: "-u"
- Proxy settings
proxy_env: []
Example Configuration File (group_vars/xxx/connectivity-test-vars.yml)
TCP is the default protocol (no need to specify).
---
connectivity_test_destinations:
- { ip: 192.168.56.10, port: 22 }
- { ip: 192.168.56.10, port: 5000 }
- { ip: 127.0.0.1, port: 53, protocol: udp }
Example Playbook connectivity-test.yml
---
- hosts: '{{inventory}}'
become: yes
roles:
- connectivity-test
How to Run
ansible-playbook connectivity-test.yml --extra-vars "inventory=all-dev" -i hosts
To skip package installation (if you already know the packages are installed):
ansible-playbook connectivity-test.yml --extra-vars "inventory=all-dev" -i hosts --skip-tags connectivity_install_pkg
Sample Output
TASK [setup] *******************************************************************
ok: [centos7]
TASK [connectivity-test : Install necessary packages on RedHat systems] *
ok: [centos7] => (item=[u'nc'])
TASK [connectivity-test : Determine source IP based on destination IP] ***************
ok: [centos7] => (item=source ip: 127.0.0.1, destination ip: 127.0.0.1)
ok: [centos7] => (item=source ip: 127.0.0.1, destination ip: 127.0.0.1)
ok: [centos7] => (item=source ip: 192.168.56.9, destination ip: 192.168.56.10)
TASK [connectivity-test : debug] ***********************************************
TASK [connectivity-test : test network connectivity] ***************************
ok: [centos7] => (item=source ip: 192.168.56.9, destination ip: 192.168.56.10, port: 22, protocol: tcp, time: 2019-07-09 23:02:56.518272, stdout: SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.8, stderr: Connection to 192.168.56.10 22 port [tcp/ssh] succeeded!
)
ok: [centos7] => (item=source ip: 127.0.0.1, destination ip: 127.0.0.1, port: 53, protocol: udp, time: 2019-07-09 23:03:12.337049, stdout: , stderr: Connection to 127.0.0.1 53 port [udp/domain] succeeded!
)
failed: [centos7] (item=source ip: 192.168.56.9, destination ip: 192.168.56.10, port: 5000, protocol: tcp, time: 2019-07-09 23:03:33.893978, stdout: , stderr: nc: connect to 192.168.56.10 port 5000 (tcp) timed out: Operation now in progress
)
TASK [connectivity-test : debug] ***********************************************
PLAY RECAP *********************************************************************
centos7 : ok=3 changed=0 unreachable=0 failed=1
Manual Check
To manually test connectivity, you can use this command:
dIP="192.168.56.10 192.168.56.13";
dPORT="5000";
sIP=$(/sbin/ip route get "$(echo $dIP | awk -F" " 'NR==1{print $1}')" | awk 'NR==1{print $NF}');
uname -n;
echo "Source IP: $sIP";
for i in $dIP;
do date;
nc -v -w 3 -s "$sIP" "$i" "$dPORT";
echo " ";
done
Informazioni sul progetto
Role to test for network issues to specified IP and port (TCP or UDP) from your Ansible hosts.
Installa
ansible-galaxy install ryandaniels.connectivity_test
Licenza
mit
Download
5k
Proprietario
Ansible all the things