【发布时间】:2020-07-08 14:44:15
【问题描述】:
我卡住了,希望你能帮助我
我想基于以下带有 vars 的 yml 文件构建文件:
---
users:
- name: "user1"
db:
- name: "main"
default_privileges:
tables: ['ALL']
sequences: ['ALL']
functions: ['EXECUTE']
types: ['USAGE']
schema:
- name: "public"
owner: no
default_privileges:
tables: ['ALL']
sequences: ['ALL']
functions: ['EXECUTE']
types: ['USAGE']
- name: "notpublic"
owner: no
default_privileges:
tables: ['ALL']
sequences: ['ALL']
functions: ['EXECUTE']
types: ['USAGE']
- name: "user2"
db:
- name: "main2"
default_privileges:
tables: ['ALL']
sequences: ['ALL']
functions: ['EXECUTE']
types: ['USAGE']
schema:
- name: "public"
owner: no
default_privileges:
tables: ['ALL']
sequences: ['ALL']
functions: ['EXECUTE']
types: ['USAGE']
- name: "nonpublic"
owner: no
default_privileges:
tables: ['ALL']
sequences: ['ALL']
functions: ['EXECUTE']
types: ['USAGE']
如何遍历 Jinja 模板中声明的模式列表? 如果我使用以下构造
{% for user in users %}
{% for userdb in user.db %}
{% for s in userdb.schema %}
{{ s.name }}
{% endfor %}
{% endfor %}
{% endfor %}
在执行过程中出现以下错误:
FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'schema'"}
【问题讨论】:
-
在从模板创建文件之前,在您的剧本中某处调试
users对象,因为根据下面的@JGK 回答,它显然不包含您认为的内容。