In case you heard about data tagging in the past and are wondering when we’ll finally have it, there are some news regarding that: There is now a public PR in ansible/ansible with the current WIP implementation: [WIP] Templating overhaul, implement Data Tagging by nitzmahone · Pull Request #84621 · ansible/ansible · GitHub
This is highly experimental and far from done (as far as I understand), and will take some time to get completed. It’s also a very massive change, and there are still quite a few known issues (see for example the changelog fragments included in the PR). For that reason, please refrain from commenting in that PR unless absolutely necessary - it’s easier to ask somewhere else first whether the comment is appropriate (like in this thread, generally in the forum, or on Matrix or IRC).
Anyway, I want to start this thread with a little test module that uses data tagging to mark a return value as deprecated:
#!/usr/bin/python
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.datatag import AnsibleTagHelper
from ansible.module_utils.datatag.tags import Deprecated
def main():
m = AnsibleModule(argument_spec=dict())
m.exit_json(
a='normal result',
b=AnsibleTagHelper.tag('deprecated result', Deprecated(msg="Yo, this is deprecated!", removal_version="2.3.4")),
)
if __name__ == '__main__':
main()
When registering the result and using the deprecated return value, you get:
TASK [Output result B] ***********************************************************************************************************************************************************************
[WARNING]: Deprecation warnings can be disabled by setting `deprecation_warnings=False` in ansible.cfg.
[DEPRECATION WARNING]: Yo, this is deprecated! This feature will be removed in version 2.3.4.
Origin: /path/to/playbook.yml:13:14
11 - name: Output result B
12 debug:
13 msg: "{{ result.b }}"
^ column 14
ok: [localhost] => {
"msg": "deprecated result"
}
If you don’t use the deprecated return value, no deprecation message will be shown. (See my gist for a playbook and full result.)
Please note that right now the Deprecated
tag does not allow to specify the collection’s name (as opposed to the module.deprecated()
call). I’m sure this will get added (it should be pretty simple to add actually, the hard work is all the other functionality and machinery tagging needs).
It should also be pretty simple to add a module utils to a collection that does try
/catch
around the data tagging imports to provide some convenience functionality to your collection to tag data if the user uses ansible-core 2.19+, and to not use it or older verisons. That will allow collections to use this feature once it’s released, without having to wait until all ansible-core versions supported by your collections have it (which tends to need a few years longer).
Please use this thread to discuss this, share ideas, tests, etc.!