ansible - 是否可以使用 Ansible Playbook 将 with_dict 和 with_nested 一起循环?

标签 ansible

我正在尝试像这样循环哈希和与其关联的数组:

变量:

  dictionary:
    aword: [ ant, den ]
    bword: [ fat, slim ]

任务:

name: Create symlinks
command: do something with item[0] over item[1]
with_nested:
  - "{{ item.key }}"
  - "{{ item.value }}"
with_dict: dictionary

这不起作用。是我做错了什么还是 Ansible 不支持这样的迭代?

最佳答案

我使用

解决了这个问题
with_subelements

像这样

变量:

dictionary:
- name: aword
  words:
    - ant
    - den
- name: bword
  words:
    - fat
    - slim

任务:

name: Create symlinks
command: do something with item.0.name over item.1
with_subelements: 
  - dictionary
  - words

关于ansible - 是否可以使用 Ansible Playbook 将 with_dict 和 with_nested 一起循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35145454/

相关文章:

python - [可靠];使用多个字典

检查模式下 Ansible undefined variable

variables - Ansible:如何在我的剧本中使用 list 文件(主机)中定义的变量?

kubernetes - Vagrant:在所有虚拟机启动后运行 Ansible 配置,Ansible 无法连接到所有主机

centos - 如何使用 Ansible 删除 ufw 中预定义的 mDNS 规则?

variables - 如何解析 Ansible group_vars 字典中的变量?

ansible - Ansible AWX/Tower 可以使用来自外部源/Git 存储库的 group_vars 和 host_vars 吗?

ssh - Ansible:当包版本大于或等于时执行某些操作

mysql - 使用 Ansible 创建 MySQL 表

ansible - 尝试使用 ansible 在 vi​​rtualenv 中安装时权限被拒绝