From 5eff114be7009046302b06b5b0de93dfdd1f6848 Mon Sep 17 00:00:00 2001 From: Jacob Callahan Date: Tue, 26 Nov 2024 13:42:05 -0500 Subject: [PATCH] Fix for ruamel interactions with awxkit objects Cole encountered an issue where inventory syncs were failing because ruamel wasn't able to handle awxkit's Psuedonamespace objects. This simply adds a new representer for them, fixing the issue. --- broker/providers/ansible_tower.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/broker/providers/ansible_tower.py b/broker/providers/ansible_tower.py index 6684a2e..1251ff3 100644 --- a/broker/providers/ansible_tower.py +++ b/broker/providers/ansible_tower.py @@ -10,7 +10,7 @@ from logzero import logger from broker import exceptions -from broker.helpers import eval_filter, find_origin +from broker.helpers import eval_filter, find_origin, yaml from broker.settings import settings try: @@ -21,6 +21,12 @@ from broker import helpers from broker.providers import Provider +# ruamel has a hard time with PseudoNamespace objects +yaml.representer.add_representer( + awxkit.utils.PseudoNamespace, + lambda dumper, data: dumper.represent_dict(dict(data)), +) + def convert_pseudonamespaces(attr_dict): """Recursively convert PsuedoNamespace objects into dictionaries."""