需要在Ansible中使用主机变量(Ansible引擎2.8和Ansible塔3.5)

需要在Ansible中使用主机变量(Ansible引擎2.8和Ansible塔3.5),ansible,ansible-inventory,Ansible,Ansible Inventory,需要您的帮助以实现以下目标: -在Ansible资源清册中使用与hostIP内联提供的变量(即主机变量) 我的库存: [ora_patch] 10.24.29.14 SID=orcl,orcl2 我的剧本: --- - hosts: [ora_patch] tasks: - debug: var: "{{ hostvars[ansible_host]['SID'] }}" 输出**我得到**: 输出**我想要**: 我执行的命令: ansible-playbook -i i

需要您的帮助以实现以下目标: -在Ansible资源清册中使用与hostIP内联提供的变量(即主机变量)

我的库存:

[ora_patch]
10.24.29.14 SID=orcl,orcl2
我的剧本:

---
- hosts: [ora_patch]
  tasks:
  - debug:
     var: "{{ hostvars[ansible_host]['SID'] }}"
输出**我得到**: 输出**我想要**: 我执行的命令:

ansible-playbook -i inventory patch_ora_si_122.yml

Ansible inventory.ini遵循以下格式

[hosts]

[hosts:vars]
以下各项应能正常工作:

[ora_patch]
10.24.29.14 SID=orcl,orcl2

[ora_patch:vars]
SID=orcl,orcl2

Ansible inventory.ini遵循以下格式

[hosts]

[hosts:vars]
以下各项应能正常工作:

[ora_patch]
10.24.29.14 SID=orcl,orcl2

[ora_patch:vars]
SID=orcl,orcl2

你的剧本有点错。您正试图使用hostvar
的内容“{{hostvars[ansible\u host]['SID']}}”
作为变量名,以显示
debug:var=…

只需将您的剧本更改为

---
- hosts: ora_patch
  tasks:
  - debug:
     msg: "SID: {{ hostvars[ansible_host]['SID'] }}"
也可以直接使用变量名:

---
- hosts: ora_patch
  tasks:
  - debug:
     var: SID

你的剧本有点错。您正试图使用hostvar
的内容“{{hostvars[ansible\u host]['SID']}}”
作为变量名,以显示
debug:var=…

只需将您的剧本更改为

---
- hosts: ora_patch
  tasks:
  - debug:
     msg: "SID: {{ hostvars[ansible_host]['SID'] }}"
也可以直接使用变量名:

---
- hosts: ora_patch
  tasks:
  - debug:
     var: SID