[英]Ansible with_subelements nested levels
我正在嘗試遍歷嵌套循環,就像這個問題一樣:
不過,我需要進一步深入。 該評論(日期為2017年1月)指出,不支持其他級別的嵌套。 還是這樣嗎? 如果沒有,我該如何參考更深層次?
我的資料:
dns:
- name: Something
prefix: st
zones:
- zone: something.com
records:
- record: testing.something.com
type: TXT
value: '"somethingtest"'
ttl: 60
- name: Devthing
prefix: dt
zones:
- zone: devthing.com
records:
- record: testing.devthing.com
type: TXT
value: '"devthingtest"'
ttl: 60
- zone: testthing.com
records:
- record: testing.testthing.com
type: TXT
value: '"testthingtest"'
ttl: 60
- record: thingy.testthing.com
type: TXT
value: '"testthingthingytest"'
ttl: 60
我的任務:
- name: Create DNS records
route53:
state: present
zone: "{{ item.0.zone }}"
record: "{{ item.1.record }}"
type: "{{ item.1.type }}"
ttl: "{{ item.1.ttl }}"
value: "{{ item.1.value }}"
with_subelements:
- "{{ dns }}"
- records
區域,用戶和訪問策略已成功創建,因為它們無需再深入(記錄級別)。
如果您不需要根字典的name
和prefix
,則可以將原始列表簡化為區域的簡單列表:
with_subelements:
- "{{ dns | map(attribute='zones') | list | sum(start=[]) }}"
- records
並且-不-仍然不支持嵌套子元素。
在需要父選項的情況下進行更新 ,需要一些預處理:
- set_fact:
zones_loop: >
{{ zones_loop|d([])
+ [ {} | combine(item[0]) | combine(item[1]) ]
}}
with_subelements:
- "{{ dns }}"
- zones
- debug:
msg: "{{ item }}"
with_subelements:
- "{{ zones_loop }}"
- records
在第一個任務中,我們遍歷每個zone
並在其上附加/組合父項的鍵,從而形成新的zones_loop
列表。 第二項任務是相同的,但是我們遍歷了生成的列表。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.