Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a dictionary of dictionaries into a list of dictionaries in a Ansible vars file?

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.

Input:

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

Desired output:

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

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

like image 229
Jeff Widman Avatar asked May 17 '16 22:05

Jeff Widman


1 Answers

{{ postgres_users.values() | list }} seems to do it.

like image 109
Jeff Widman Avatar answered Nov 13 '22 00:11

Jeff Widman