如何将字典词典转换为Ansible

如何将字典词典转换为Ansible

本文介绍了如何将字典词典转换为Ansible vars文件中的字典列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Ansible vars文件中,我想将一则dict转换成一列字典,我可以将其从Ansible Galaxy传递给外部角色.

Within an Ansible vars file, I want to convert a dict of dicts into a list of dicts that I can pass to an external role from Ansible Galaxy.

输入:

postgres_users:
  dc1:
    name: user_dc1
    password: pass_dc1
  dc2:
    name: user_dc2
    password: pass_dc2
  dc3:
    name: user_dc3
    password: pass_dc3

所需的输出:

postgres_users:
  - name: user_dc1
    password: pass_dc1
  - name: user_dc2
    password: pass_dc2
  - name: user_dc3
    password: pass_dc3

在Ansible vars文件中是否有一种简单的方法?

Is there a simple way to do this within an Ansible vars file?

推荐答案

{{ postgres_users.values() | list }} 似乎做到了.

这篇关于如何将字典词典转换为Ansible vars文件中的字典列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 04:06