mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 04:40:22 -07:00
ini_file: add allow_no_value param (#24442)
This commit is contained in:
parent
7d0e1f92f4
commit
daeec920b0
2 changed files with 159 additions and 10 deletions
|
@ -115,9 +115,139 @@
|
|||
set_fact:
|
||||
content5: "{{ lookup('file', output_file) }}"
|
||||
|
||||
- name: assert changed
|
||||
- name: assert changed and content is empty
|
||||
assert:
|
||||
that:
|
||||
- result5.changed == True
|
||||
- result5.msg == 'section removed'
|
||||
- content5 == ""
|
||||
|
||||
# allow_no_value
|
||||
|
||||
- name: test allow_no_value
|
||||
ini_file:
|
||||
path: "{{ output_file }}"
|
||||
section: mysqld
|
||||
option: skip-name
|
||||
allow_no_value: yes
|
||||
register: result6
|
||||
|
||||
- name: assert section and option added
|
||||
assert:
|
||||
that:
|
||||
- result6.changed == True
|
||||
- result6.msg == 'section and option added'
|
||||
|
||||
- name: test allow_no_value idempotency
|
||||
ini_file:
|
||||
path: "{{ output_file }}"
|
||||
section: mysqld
|
||||
option: skip-name
|
||||
allow_no_value: yes
|
||||
register: result6
|
||||
|
||||
- name: assert 'changed' false
|
||||
assert:
|
||||
that:
|
||||
- result6.changed == False
|
||||
- result6.msg == 'OK'
|
||||
|
||||
- name: test allow_no_value with loop
|
||||
ini_file:
|
||||
path: "{{ output_file }}"
|
||||
section: mysqld
|
||||
option: "{{ item.o }}"
|
||||
value: "{{ item.v }}"
|
||||
allow_no_value: yes
|
||||
with_items:
|
||||
- { o: "skip-name-resolve", v: null }
|
||||
- { o: "max_connections", v: "500" }
|
||||
|
||||
- name: set expected content and get current ini file content
|
||||
set_fact:
|
||||
content7: "{{ lookup('file', output_file) }}"
|
||||
expected7: |-
|
||||
|
||||
[mysqld]
|
||||
skip-name
|
||||
skip-name-resolve
|
||||
max_connections = 500
|
||||
|
||||
- name: Verify content of ini file is as expected
|
||||
assert:
|
||||
that:
|
||||
- content7 == expected7
|
||||
|
||||
- name: change option with no value to option with value
|
||||
ini_file:
|
||||
path: "{{ output_file }}"
|
||||
section: mysqld
|
||||
option: skip-name
|
||||
value: myvalue
|
||||
register: result8
|
||||
|
||||
- name: set expected content and get current ini file content
|
||||
set_fact:
|
||||
content8: "{{ lookup('file', output_file) }}"
|
||||
expected8: |-
|
||||
|
||||
[mysqld]
|
||||
skip-name = myvalue
|
||||
skip-name-resolve
|
||||
max_connections = 500
|
||||
|
||||
- name: assert 'changed' and msg 'option changed' and content is as expected
|
||||
assert:
|
||||
that:
|
||||
- result8.changed == True
|
||||
- result8.msg == 'option changed'
|
||||
- content8 == expected8
|
||||
|
||||
- name: change option with value to option with no value
|
||||
ini_file:
|
||||
path: "{{ output_file }}"
|
||||
section: mysqld
|
||||
option: skip-name
|
||||
allow_no_value: yes
|
||||
register: result9
|
||||
|
||||
- name: set expected content and get current ini file content
|
||||
set_fact:
|
||||
content9: "{{ lookup('file', output_file) }}"
|
||||
expected9: |-
|
||||
|
||||
[mysqld]
|
||||
skip-name
|
||||
skip-name-resolve
|
||||
max_connections = 500
|
||||
|
||||
- name: assert 'changed' and msg 'option changed' and content is as expected
|
||||
assert:
|
||||
that:
|
||||
- result9.changed == True
|
||||
- result9.msg == 'option changed'
|
||||
- content9 == expected9
|
||||
|
||||
- name: Remove option with no value
|
||||
ini_file:
|
||||
path: "{{ output_file }}"
|
||||
section: mysqld
|
||||
option: skip-name-resolve
|
||||
state: absent
|
||||
register: result10
|
||||
|
||||
- name: set expected content and get current ini file content
|
||||
set_fact:
|
||||
content10: "{{ lookup('file', output_file) }}"
|
||||
expected10: |-
|
||||
|
||||
[mysqld]
|
||||
skip-name
|
||||
max_connections = 500
|
||||
|
||||
- name: assert 'changed' and msg 'option changed' and content is as expected
|
||||
assert:
|
||||
that:
|
||||
- result10.changed == True
|
||||
- result10.msg == 'option changed'
|
||||
- content10 == expected10
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue