Skip to content

Instantly share code, notes, and snippets.

@dekimsey
Last active August 12, 2016 19:31
Show Gist options
  • Save dekimsey/45aeb95814b4aa878ab3f0e5d2d3cb8f to your computer and use it in GitHub Desktop.
Save dekimsey/45aeb95814b4aa878ab3f0e5d2d3cb8f to your computer and use it in GitHub Desktop.
ini_file doesn't support multiline keys
*.array
*.inline
#!/usr/bin/env python
import sys
from ConfigParser import SafeConfigParser
orig_fn, other_fn = sys.argv[1:]
orig_c = SafeConfigParser()
orig_c.read(orig_fn)
other_c = SafeConfigParser()
other_c.read(other_fn)
if orig_c.get('foo', 'bar') == other_c.get('foo', 'bar'):
sys.exit(0)
sys.exit(1)
---
- name: Reset tests
hosts: localhost
become: false
connection: local
tasks:
- name: Clean-up demo
command: find . -depth 1 -name '*.ini.*' -delete
- name: DEMO 1; multiline inline fails
hosts: localhost
become: false
connection: local
tasks:
- block:
- command: cp -f working.ini multiline.ini.inline
- name: Set multiline.ini.inline
ini_file:
dest: multiline.ini.inline
section: foo
option: bar
value: |
line 1
line 2
line 3
- name: Test multiline.ini.inline works ok
command: python diff-ini.py working.ini multiline.ini.inline
changed_when: false
rescue:
# empty rescue block won't trigger the error catching, so lets create a dummy
- debug: msg="Trying to set an inline multiline value failed"
- name: DEMO 2; it'd be cool if array serialization was supported
hosts: localhost
become: false
connection: local
tasks:
- block:
- command: cp -f working.ini multiline.ini.array
- name: Try multiline.ini with an array
ini_file:
dest: multiline.ini.array
section: foo
option: bar
value: ["line 1", "line 2", "line 3"]
- name: Test multiline.ini.array works ok
command: python diff-ini.py working.ini multiline.ini.array
changed_when: false
rescue:
# empty rescue block won't trigger the error catching, so lets create a dummy
- debug: msg="Trying to set an inline multiline array value failed"
[foo]
baz = simple value
bar = line 1
line 2
line 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment