ryandaniels.connectivity_test

ansible-role-connectivity-test

nc (netcat)を使って、指定したIPとポート(TCPまたはUDP)のネットワークの問題をテストします。
使用可能なルートから目的のIPに基づいて動的に使用するソースIPを決定します。

デフォルトではTCPプロトコルを使用します。UDPをテストに必要な場合は、protocol: udpを指定できます。

テスト済みのディストリビューション

  • Ubuntu 18.04 / 16.04
  • CentOS / RHEL: 7.x, 6.5, 5.9

依存関係

OSコマンド:

  • nc (netcat) - 存在しない場合はインストールされます
  • ip
  • awk

デフォルト設定

  • デバッグの有効化
debug_enabled_default: false
  • タイムアウト
connectivity_test_wait_default: 5
  • 設定で'udp'が指定されている場合に使用するUDP引数
connectivity_test_udp_command: "-u"
  • プロキシ
proxy_env: []

例の設定ファイル (group_vars/xxx/connectivity-test-vars.yml)

デフォルトでTCPプロトコルが使用されます(指定する必要はありません)。

---
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 }

例のプレイブック connectivity-test.yml

---
- hosts: '{{inventory}}'
  become: yes
  roles:
  - connectivity-test

使用法

ansible-playbook connectivity-test.yml --extra-vars "inventory=all-dev" -i hosts

パッケージのインストールをスキップする(既にある場合 - タスクの速度向上)

ansible-playbook connectivity-test.yml --extra-vars "inventory=all-dev" -i hosts --skip-tags connectivity_install_pkg

例の出力

TASK [setup] *******************************************************************
ok: [centos7]

TASK [connectivity-test : Install dependant packages in RedHat based machines] *
ok: [centos7] => (item=[u'nc'])

TASK [connectivity-test : Get 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  

手動方法

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 "Src IP: $sIP";
for i in $dIP;
do date;
nc -v -w 3 -s "$sIP" "$i" "$dPORT";
echo " ";
done
プロジェクトについて

Role to test for network issues to specified IP and port (TCP or UDP) from your Ansible hosts.

インストール
ansible-galaxy install ryandaniels.connectivity_test
ライセンス
mit
ダウンロード
5k
所有者
Ansible all the things