[PR #10852/648ff7db backport][stable-11] yaml cache plugin: make compatible with ansible-core 2.19 (#10856)

yaml cache plugin: make compatible with ansible-core 2.19 (#10852)

Make compatible with ansible-core 2.19.

(cherry picked from commit 648ff7db02)

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
patchback[bot] 2025-09-25 20:34:42 +02:00 committed by GitHub
commit de8d1760c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 4 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "yaml cache plugin - make compatible with ansible-core 2.19 (https://github.com/ansible-collections/community.general/issues/10849, https://github.com/ansible-collections/community.general/issues/10852)."

View file

@ -44,8 +44,7 @@ options:
# TODO: determine whether it is OK to change to: type: float # TODO: determine whether it is OK to change to: type: float
""" """
import os
import codecs
import yaml import yaml
@ -60,9 +59,9 @@ class CacheModule(BaseFileCacheModule):
""" """
def _load(self, filepath): def _load(self, filepath):
with codecs.open(filepath, 'r', encoding='utf-8') as f: with open(os.path.abspath(filepath), 'r', encoding='utf-8') as f:
return AnsibleLoader(f).get_single_data() return AnsibleLoader(f).get_single_data()
def _dump(self, value, filepath): def _dump(self, value, filepath):
with codecs.open(filepath, 'w', encoding='utf-8') as f: with open(os.path.abspath(filepath), 'w', encoding='utf-8') as f:
yaml.dump(value, f, Dumper=AnsibleDumper, default_flow_style=False) yaml.dump(value, f, Dumper=AnsibleDumper, default_flow_style=False)