mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-07-08 19:49:09 +00:00
Add `from_toml` filter (#12081) (#12081)
* Add `from_toml` filter (#12081)
* Use tasks/main.yml instead of runme.sh for integration tests
* Renamed filter back to to_toml.py, moved from_toml filter to its own file making use of python's native tomllib
* Remove task to install tomlkit library as it's no longer required for the from_toml filter
* Replace deprecated t.Mapping with collections.abc.Mapping (https://docs.python.org/3/library/typing.html#typing.Mapping)
* Type is not determined when function is called. Let isinstance check ensure value has string type.
(cherry picked from commit 8faf8c3838)
Co-authored-by: spike77453 <spike77453@users.noreply.github.com>
This commit is contained in:
parent
ab08561421
commit
06feb91f2b
5 changed files with 131 additions and 0 deletions
12
tests/integration/targets/filter_from_toml/tasks/main.yml
Normal file
12
tests/integration/targets/filter_from_toml/tasks/main.yml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
- name: Convert TOML string to dictionary
|
||||
set_fact:
|
||||
actual_dict: "{{ toml_document | community.general.from_toml }}"
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- expected_dict == actual_dict
|
||||
54
tests/integration/targets/filter_from_toml/vars/main.yml
Normal file
54
tests/integration/targets/filter_from_toml/vars/main.yml
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
toml_document: |-
|
||||
# This is a TOML document
|
||||
|
||||
title = "TOML Example"
|
||||
|
||||
[owner]
|
||||
name = "Tom Preston-Werner"
|
||||
dob = 1979-05-27T07:32:00-08:00
|
||||
|
||||
[database]
|
||||
enabled = true
|
||||
ports = [ 8000, 8001, 8002 ]
|
||||
data = [ ["delta", "phi"], [3.14] ]
|
||||
temp_targets = { cpu = 79.5, case = 72.0 }
|
||||
|
||||
[servers]
|
||||
|
||||
[servers.alpha]
|
||||
ip = "10.0.0.1"
|
||||
role = "frontend"
|
||||
|
||||
[servers.beta]
|
||||
ip = "10.0.0.2"
|
||||
role = "backend"
|
||||
|
||||
expected_dict:
|
||||
"title": "TOML Example"
|
||||
"owner":
|
||||
"name": "Tom Preston-Werner"
|
||||
"dob": 1979-05-27T07:32:00-08:00
|
||||
"database":
|
||||
"enabled": true
|
||||
"ports":
|
||||
- 8000
|
||||
- 8001
|
||||
- 8002
|
||||
"data":
|
||||
- ["delta", "phi"]
|
||||
- [3.14]
|
||||
"temp_targets":
|
||||
"case": 72.0
|
||||
"cpu": 79.5
|
||||
"servers":
|
||||
"alpha":
|
||||
"ip": "10.0.0.1"
|
||||
"role": "frontend"
|
||||
"beta":
|
||||
"ip": "10.0.0.2"
|
||||
"role": "backend"
|
||||
Loading…
Add table
Add a link
Reference in a new issue