ansible - 如何从特定主机的清单中访问 ip_address?
问题描述
库存看起来像:
[host-1]
h1 ansible_ssh_private_key_file="*/*/*" ansible_host=a.b.c.d
h2 ansible_ssh_private_key_file="*/*/*" ansible_host=a.b.c.t
[host-2]
h3 ansible_ssh_private_key_file="*/*/*" ansible_host=a.b.c.r
我想在模板中使用 ansible_host oh 'h2'但我收到ansible.errors.AnsibleUndefinedVariable错误。如何解决?
我已经尝试过这些:
1. "{{hostvars['host-2'][h2][ansible_host]}}"
2. "{{hostvars[host-2][h2][ansible_host]}}"
3. "{{hostvars['host-2'][h2].ansible_host}}"
4. "{{hostvars[groups['host-2'][h2]].ansible_host}}"
解决方案
请作为提示:
- name: host
debug: msg="{{hostvars['h2']['ansible_host']}}"
推荐阅读
- python - 如何使用 winwifi 包中的 scan() 方法
- f# - 当 stream.UserState 更新时,FParsec 'many' 原语失败
- qml - QML: Implement custom control with rectangles
- c++ - 为什么我们需要语法产生式基本说明符的最后两个定义?
- javascript - 根据可拖动 div 的状态添加/删除类
- html - Angular Primeng 轮播 - 自定义上一个和下一个按钮
- android - Unity Android 64 位 - 不兼容错误
- html - 如何在博客中编辑 URL 标签而不丢失任何帖子?
- c# - MineSweeper 中的递归函数给出 stackoverflow 错误
- sql - 人口稀少的表上的自联接