我正在尝试通过不起作用的以下过程获取清单主机组名称
- debug:
msg: "{{ groups['{{ item }}'] }}"
with_items: "{{ vm.stdout_lines }}"
这实际上是我想要做的 我将通过外壳脚本获得服务器列表
- name: Getting the servers list
shell: |
sh getServers.sh
register: vm
然后通过add_host将它们添加到库存中
- name: Creating Logical host_group for each server
add_host:
name: "{{ item }}"
groups: ["{{item }}"]
with_items: "{{ vm.stdout_lines }}"
register: inv
在这里,我尝试获取在上述步骤中添加的唯一组,而不是所有组
- debug:
msg: "{{ groups['{{ item }}'] }}"
with_items: "{{ vm.stdout_lines }}"
错误是
{"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute '{{ item }}'
对此有所帮助!
答案 0 :(得分:1)
修复语法
msg: "{{ groups[item] }}"