我被困在一个可能很容易的任务上。我有一个深层嵌套的词典 有3个级别:
---
postgres:
user: postgres
password: test123
hosts:
- host: localhost
user: postgres
password: test123
users:
- user: bm
password: 123
databases:
- bm
- bm2
- user: bm_test
password: 123
databases:
- bm_test
filebeat:
- document_type: syslog
paths:
- /var/log/syslog
现在Ansible创建了一个新用户:
- name: create postgres users
postgresql_user:
login_host: "{{ item.0.host }}"
login_user: "{{ item.0.user }}"
login_password: "{{ item.0.password }}"
name: "{{ item.1.user }}"
password: "{{ item.1.password }}"
encrypted: yes
# priv: "CONNECT/products:ALL"
with_subelements:
- "{{ postgres.hosts|default([]) }}"
- users
现在我陷入了困境:
- name: create databases
postgresql_db:
login_host: "{{ item.0.host }}"
login_user: "{{ item.0.user }}"
login_password: "{{ item.0.password }}"
name: "{{ item.1 }}"
with_subelements:
- "{{ postgres.hosts|default([]) | sum(attribute='users', start=[]) | list }}"
- databases
这里的问题是item.0.host,user&密码未定义。我该怎么办?
由于 添