Skip to content

Commit

Permalink
labels - AT provider - fix label value parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
rplevka committed Apr 17, 2024
1 parent 83721f0 commit 6897512
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions broker/providers/ansible_tower.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,13 @@ def _resolve_labels(self, labels, target):
"""
label_ids = []
for label in labels:
if result := self.v2.labels.get(name=label).results:
label_expanded = f"{label}={labels[label]}"
if result := self.v2.labels.get(name=label_expanded).results:
label_ids.append(result[0].id)
else:
# label does not exist yet, creating
result = self.v2.labels.post(
{"name": label, "organization": target.summary_fields.organization.id}
{"name": label_expanded, "organization": target.summary_fields.organization.id}
)
if result:
label_ids.append(result.id)
Expand Down Expand Up @@ -594,10 +595,7 @@ def execute(self, **kwargs): # noqa: PLR0912,PLR0915 - Possible TODO refactor
payload["labels"] = self._resolve_labels(labels, target)
# record labels also as extra vars - use key=value format
kwargs.update(
{
f"_broker_label_{label[0]}": "=".join(label[1:])
for label in [kv_pair.split("=") for kv_pair in labels]
}
{f"_broker_label_{label[0]}": "=".join(label[1:]) for label in labels.items()}
)
elif self.inventory:
payload["inventory"] = self.inventory
Expand Down

0 comments on commit 6897512

Please sign in to comment.