我想写一个简单的ping攻略,它从HOST_VARS中的所有YAML文件中获取IP地址,并连接到Linux设备,并Ping所有收集的IP示例: HOST_VARS:-server1.yml (包含IP = 1.1.1.1) -server2.yml (包含IP = 2.2.2)。攻略将连接到所有linux设备,并使用提取的IP测试到这些设备(在本例中为1.1.1.1和2.2.2.2)的连通性
这就是可能的解决方案,但缺少一些东西:
- name: "Ping all Linux VMs"
hosts: servers
gather_facts: no
tasks:
- debug:
msg: "{{ hostvars['{{ item }}'].ansible_host }}"
with_items: "{{ groups['servers'] }}"
delegate_to: localhost这是我的清单:
[centos@Ansible silverpeak-cisco-poc-automation]$ ansible-inventory --graph
@all:
|--@servers:
| |--backbone1_linux
| |--backbone2_linux
| |--linux1
| |--linux2
| |--linux3
| |--linux4
|--@ungrouped:示例:
Playbook将连接到backbone1_linux并ping组服务器的所有剩余成员
有人能在这个问题上帮我吗?
发布于 2020-09-03 07:38:21
调试任务应显示IP地址
- hosts: servers
gather_facts: false
tasks:
- debug:
msg: "{{ hostvars[item]['IP'] }}"
loop: "{{ groups.servers }}"
delegate_to: localhost
run_once: true下面的命令任务应该ping通IP地址
- command: "ping -c 1 {{ hostvars[item]['IP'] }}"
loop: "{{ groups.servers }}"
delegate_to: localhost
run_once: truehttps://stackoverflow.com/questions/63714324
复制相似问题