0
私は以下のリストをAnsibleに入れ、フラットな構造を得たいと考えています。 入力:可能なリストフラット
[
{
id: "one",
level: "3"
},
{
id: "two",
level: "8"
},
...
]
所望の出力:
[
{
one: "3"
},
{
two: "8"
},
...
]
私は以下のリストをAnsibleに入れ、フラットな構造を得たいと考えています。 入力:可能なリストフラット
[
{
id: "one",
level: "3"
},
{
id: "two",
level: "8"
},
...
]
所望の出力:
[
{
one: "3"
},
{
two: "8"
},
...
]
ボックスのうち簡単な方法はありません。
カスタム template filterいずれかを使用でき:
my_list | map('template','{"<<item.id>>":"<<item.level>>"}',from_json=true) | list
それともset_fact
+ register
+ with_items
で新しい変数を生成し、Process complex variables with set_fact and with_itemsを参照してください。
- set_fact:
tmp_item: '{ "{{ item.id }}": "{{ item.level }}" }'
with_items: "{{ my_list }}"
register: tmp_list
- debug:
msg: "{{ tmp_list.results | map(attribute='ansible_facts.tmp_item') | list }}"