|
3 | 3 | # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
4 | 4 | # SPDX-License-Identifier: GPL-3.0-or-later |
5 | 5 |
|
6 | | -- name: 'Define ini_test_dict' |
7 | | - ansible.builtin.set_fact: |
8 | | - ini_test_dict: |
9 | | - section_name: |
10 | | - key_name: 'key value' |
11 | | - |
12 | | - another_section: |
13 | | - connection: 'ssh' |
14 | | - |
15 | | - interpolate_test: |
16 | | - interpolate_test_key: '%' |
17 | | - |
18 | | -- name: 'Write INI file that reflects ini_test_dict to {{ ini_test_file }}' |
19 | | - ansible.builtin.copy: |
20 | | - dest: '{{ ini_test_file }}' |
21 | | - content: | |
| 6 | +- name: Basic test |
| 7 | + ansible.builtin.assert: |
| 8 | + that: |
| 9 | + - ini_file_content | community.general.from_ini == ini_test_dict |
| 10 | + vars: |
| 11 | + ini_file_content: | |
22 | 12 | [section_name] |
23 | 13 | key_name = key value |
24 | 14 |
|
25 | 15 | [another_section] |
26 | 16 | connection = ssh |
27 | 17 |
|
| 18 | + [empty section] |
| 19 | +
|
28 | 20 | [interpolate_test] |
29 | 21 | interpolate_test_key = % |
30 | | -
|
31 | | -- name: 'Slurp the test file: {{ ini_test_file }}' |
32 | | - ansible.builtin.slurp: |
33 | | - src: '{{ ini_test_file }}' |
34 | | - register: 'ini_file_content' |
35 | | - |
36 | | -- name: >- |
37 | | - Ensure defined ini_test_dict is the same when retrieved |
38 | | - from {{ ini_test_file }} |
39 | | - ansible.builtin.assert: |
40 | | - that: |
41 | | - - 'ini_file_content.content | b64decode | community.general.from_ini == |
42 | | - ini_test_dict' |
43 | | - |
44 | | -- name: 'Define another ini_test_dict' |
45 | | - ansible.builtin.set_fact: |
46 | 22 | ini_test_dict: |
47 | 23 | section_name: |
48 | | - 'key_name * : with spaces': 'key value' |
| 24 | + key_name: key value |
49 | 25 |
|
50 | | -- name: 'Write another INI file that reflects ini_test_dict to {{ ini_test_file }}' |
51 | | - ansible.builtin.copy: |
52 | | - dest: '{{ ini_test_file }}' |
53 | | - content: | |
54 | | - [section_name] |
55 | | - key_name * : with spaces = key value |
| 26 | + another_section: |
| 27 | + connection: ssh |
56 | 28 |
|
57 | | -- name: 'Slurp the other test file: {{ ini_test_file }}' |
58 | | - ansible.builtin.slurp: |
59 | | - src: '{{ ini_test_file }}' |
60 | | - register: 'ini_file_content' |
| 29 | + empty section: {} |
61 | 30 |
|
62 | | -- name: >- |
63 | | - Ensure defined ini_test_dict is the same when retrieved |
64 | | - from other {{ ini_test_file }} |
| 31 | + interpolate_test: |
| 32 | + interpolate_test_key: '%' |
| 33 | + |
| 34 | +- name: Test delimiters |
65 | 35 | ansible.builtin.assert: |
66 | 36 | that: |
67 | | - - 'ini_file_content.content | b64decode | community.general.from_ini(delimiters=["="]) == |
68 | | - ini_test_dict' |
69 | | - |
70 | | -- name: 'Create a file that is not INI formatted: {{ ini_bad_file }}' |
71 | | - ansible.builtin.copy: |
72 | | - dest: '{{ ini_bad_file }}' |
73 | | - content: | |
74 | | - Testing a not INI formatted file. |
75 | | -
|
76 | | -- name: 'Slurp the file that is not INI formatted: {{ ini_bad_file }}' |
77 | | - ansible.builtin.slurp: |
78 | | - src: '{{ ini_bad_file }}' |
79 | | - register: 'ini_bad_file_content' |
| 37 | + - ini_file_content | community.general.from_ini(delimiters=["="]) == ini_test_dict |
| 38 | + vars: |
| 39 | + ini_file_content: | |
| 40 | + [section_name] |
| 41 | + key_name * : with spaces = key value |
| 42 | + ini_test_dict: |
| 43 | + section_name: |
| 44 | + 'key_name * : with spaces': 'key value' |
80 | 45 |
|
81 | | -- name: 'Try parsing the bad file with from_ini: {{ ini_bad_file }}' |
| 46 | +- name: Try parsing the bad file with from_ini |
82 | 47 | ansible.builtin.debug: |
83 | | - var: ini_bad_file_content | b64decode | community.general.from_ini |
84 | | - register: 'ini_bad_file_debug' |
| 48 | + var: ini_bad_file_content | community.general.from_ini |
| 49 | + vars: |
| 50 | + ini_bad_file_content: | |
| 51 | + Testing a not INI formatted file. |
| 52 | + register: ini_bad_file_debug |
85 | 53 | ignore_errors: true |
86 | 54 |
|
87 | 55 | - name: 'Ensure from_ini raised the correct exception' |
88 | 56 | ansible.builtin.assert: |
89 | 57 | that: |
| 58 | + - ini_bad_file_debug is failed |
90 | 59 | - "'from_ini failed to parse given string' in ini_bad_file_debug.msg" |
91 | 60 | - "'File contains no section headers' in ini_bad_file_debug.msg" |
92 | | -... |
0 commit comments