Skip to content

Instantly share code, notes, and snippets.

@metajiji
Created October 17, 2018 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metajiji/423825efa045585e52e4236db07b4d83 to your computer and use it in GitHub Desktop.
Save metajiji/423825efa045585e52e4236db07b4d83 to your computer and use it in GitHub Desktop.
- hosts: localhost
gather_facts: no
vars:
config_ini:
section1:
key1: value11
key2: value2
section2:
key1: value21
key2: value22
tasks:
- name: Iterate dict
debug:
var: item
with_subelements:
- "{% set d = [] %}{% for k in config_ini %}{% set _ = d.append({'section':k, 'data': lookup('dict', config_ini[k])}) %}{% endfor %}{{d}}"
- data
- name: Set ini data
ini_file:
path: "{{ playbook_dir }}/config.ini"
section: "{{ item.0.section }}"
option: "{{ item.1.key }}"
value: "{{ item.1.value }}"
mode: 0600
owner: metall
group: metall
with_subelements:
- "{% set d=[] %}{% for k in config_ini %}{% set _=d.append({'section':k, 'data':lookup('dict', config_ini[k])}) %}{% endfor %}{{d}}"
- data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment