@ -61,11 +61,11 @@
- result2.changed == False
- result2.changed == False
- result2.msg == 'OK'
- result2.msg == 'OK'
- name : Ensure " hat e=coke" is in section "[drinks]"
- name : Ensure " beverag e=coke" is in section "[drinks]"
ini_file:
ini_file:
path : "{{ output_file }}"
path : "{{ output_file }}"
section : drinks
section : drinks
option : hat e
option : beverag e
value : coke
value : coke
register : result3
register : result3
@ -75,7 +75,7 @@
[ drinks]
[ drinks]
fav = lemonade
fav = lemonade
hat e = coke
beverag e = coke
content3 : "{{ lookup('file', output_file) }}"
content3 : "{{ lookup('file', output_file) }}"
- name : assert 'changed' is true and content is OK
- name : assert 'changed' is true and content is OK
@ -85,11 +85,11 @@
- result3.msg == 'option added'
- result3.msg == 'option added'
- content3 == expected3
- content3 == expected3
- name : Remove option " hat e=coke"
- name : Remove option " beverag e=coke"
ini_file:
ini_file:
path : "{{ output_file }}"
path : "{{ output_file }}"
section : drinks
section : drinks
option : hat e
option : beverag e
state : absent
state : absent
register : result4
register : result4
@ -251,3 +251,98 @@
- result10.changed == True
- result10.changed == True
- result10.msg == 'option changed'
- result10.msg == 'option changed'
- content10 == expected10
- content10 == expected10
- name : Clean test file
copy:
content : ""
dest : "{{ output_file }}"
force : yes
- name : Ensure "beverage=coke" is created within no section
ini_file:
section:
path : "{{ output_file }}"
option : beverage
value : coke
register : result11
- name : set expected content and get current ini file content
set_fact:
expected11 : "beverage = coke"
content11 : "{{ lookup('file', output_file) }}"
- name : assert 'changed' is true and content is OK (no section)
assert:
that:
- result11 is changed
- result11.msg == 'option added'
- content11 == expected11
- name : Ensure "beverage=coke" is modified as "beverage=water" within no section
ini_file:
path : "{{ output_file }}"
option : beverage
value : water
section:
register : result12
- name : set expected content and get current ini file content
set_fact:
expected12 : "beverage = water"
content12 : "{{ lookup('file', output_file) }}"
- name : assert 'changed' is true and content is OK (no section)
assert:
that:
- result12 is changed
- result12.msg == 'option changed'
- content12 == expected12
- name : remove option 'beverage' within no section
ini_file:
section:
path : "{{ output_file }}"
option : beverage
state : absent
register : result13
- name : get current ini file content
set_fact:
content13 : "{{ lookup('file', output_file) }}"
- name : assert changed (no section)
assert:
that:
- result13 is changed
- result13.msg == 'option changed'
- content13 == ""
- name : Check add option without section before existing section
block:
- name : Add option with section
ini_file:
path : "{{ output_file }}"
section : drinks
option : beverage
value : water
- name : Add option without section
ini_file:
path : "{{ output_file }}"
section:
option : like
value : tea
- name : set expected content and get current ini file content
set_fact:
expected14 : |-
like = tea
[ drinks]
beverage = water
content14 : "{{ lookup('file', output_file) }}"
- name : Verify content of ini file is as expected
assert:
that:
- content14 == expected14