我有两台机器,需要检查机器-1必须能够通过端口-1\f25 10250 -1\f6使用TCP协议与-2\f25 machine-2 \f6通信,同样-2\f25 machine-2 \f6必须能够通过端口-1\f25 2380 -1\f6使用-1\f25 UDP -1\f6协议与机器-2\f25-1\f6通信。为此,我想使用Ansible并编写一个Ansible脚本,但我不确定如何实现这一点。请让我知道你的意见。
提前感谢
发布于 2019-02-18 14:25:46
对于我来说,仅仅是为了测试,写一本ansible剧本并不是一个好主意。但如果你想写,你可以遵循以下步骤:
结构:
库存
[UDP]
xx.xx.xx.xx
[UDP:vars]
port_number = 2380
[TCP]
xx.xx.xx.xx
[TCP:vars]
port_number = 10250攻略
---
name: play to test the port connection
hosts: "{{ hosts }}"
tasks:
- name: check if port is working.
<module_name>: .......发布于 2019-02-20 18:40:44
在这里,我已经尝试了一个ansible剧本,以满足您的需求。
- hosts: host[1:2].xxx.xx
gather_facts: False
become: yes
vars:
host1: host1.xxx.xx
host2: host2.xxx.xx
tasks:
- name: Check port from host1 to host2
wait_for: host={{host2}} port=10250 timeout=1
delegate_to: "{{host1}}"
- name: Check port from host2 to host1
wait_for: host={{host1}} port=2380 timeout=1
delegate_to: "{{host2}}"https://stackoverflow.com/questions/54741104
复制相似问题