Add `to_toml` filter (#11423)
* Add to_toml filter
This is based heavily on the to_yaml filter, but
with a pared-down feature set.
* Protect import
* Don't quote datetime as a string
* Use Ansible error types
* Import correct error types
* Don't use AnsibleTypeError
It doesn't seem to be available on older Ansible
core versions.
* Fix antsibull-nox errors
* Install dependencies for to_toml integration test
* Reduce author list to main contributor
* Update version added for to_toml
* Use AnsibleError for missing import
* Use AnsibleFilterError for runtime type check
* Move common code to plugin_utils/_tags.py
* Mark module util as private
* Update BOTMETA for to_toml
* Fix typo
* Correct version number
* Use to_text for to_toml dict key conversions
* Add tomlkit requirement to docs
* Add missing import
* Add aliases for for to_toml integration test
---------
(cherry picked from commit 864695f898)
Co-authored-by: Matt Williams <matt@milliams.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
Add type hints to action and test plugins and to plugin utils; fix some bugs, and improve input validation (#11167)
* Add type hints to action and test plugins and to plugin utils. Also fix some bugs and add proper input validation.
* Combine lines.
* Extend changelog fragment.
* Move task_vars initialization up.
---------
(cherry picked from commit 19757b3a4c)
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Use raise from in plugins (#11095)
* Use raise from.
* Add changelog fragment.
(cherry picked from commit 2b4333a033)
Co-authored-by: Felix Fontein <felix@fontein.de>
* Adjust all __future__ imports:
for i in $(grep -REl "__future__.*absolute_import" plugins/ tests/); do
sed -e 's/from __future__ import .*/from __future__ import annotations/g' -i $i;
done
* Remove all UTF-8 encoding specifications for Python source files:
for i in $(grep -REl '[-][*]- coding: utf-8 -[*]-' plugins/ tests/); do
sed -e '/^# -\*- coding: utf-8 -\*-/d' -i $i;
done
* Remove __metaclass__ = type:
for i in $(grep -REl '__metaclass__ = type' plugins/ tests/); do
sed -e '/^__metaclass__ = type/d' -i $i;
done
* Fix dependent lookup.
* Fix ansible_type plugin utils and adjust documentation of reveal_ansible_type filter and ansible_type test.
* Fix diy callback plugin.
* Adjust to Data Tagging.
* Vendor and use internal code from ansible-core to fix YAML callback.
Ref: https://github.com/ansible/ansible/issues/84781
* Replace to_native(), to_text(), str() with str() where possible or leave it away in f-string formatting.
* Improve formulation.
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
* Use more f-strings.
* Remove unicode prefix for strings.
---------
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
* Add filter replace_keys.
* Update examples and integration tests.
* Fix examples and copyright.
* Update documentation, examples and integration tests.
* Implement #8445. Add filter replace_keys
* Fix documentation formatting.
* Fix documentation.
* Fix type(target). Formatting improved.
* Instead of a dictionary, _keys_filter_target_dict returns a list
* No target testing in _keys_filter_params
* Interface changed _keys_filter_params(data, matching_parameter)
* If there are items with equal C(before) the B(first) one will be used.
* Update remove_keys. Interface changed _keys_filter_params(data, matching_parameter)
* The target can't be empty also in _keys_filter_target_dict
* Update plugins/filter/replace_keys.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* Update plugins/filter/replace_keys.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* Update plugins/filter/replace_keys.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* Test attributes before and after are strings in the iteration of target.
* Update plugins/filter/replace_keys.py
Co-authored-by: Felix Fontein <felix@fontein.de>
---------
Co-authored-by: Felix Fontein <felix@fontein.de>