Skip to content

Run-3409: Ansible model sources return host vars data in key value format when gather facts is set to no #411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

edbaltra
Copy link
Contributor

@edbaltra edbaltra commented May 24, 2025

Summary

This PR addresses an issue where host variables with structured data (such as lists or maps) — for example, the ports attribute returned by dynamic Ansible inventories like nmap — were being imported into Rundeck as flattened Java toString() representations when gather_facts was set to false.

What was done:

  • Modified createNodeEntry(...) to serialize Map and List values using Gson.toJson() instead of relying on .toString().
  • Ensured structured data (like lists of open ports) are stored as valid JSON strings in node attributes.

This change ensures consistent and parseable structured data in Rundeck’s node model, even when Ansible fact gathering is disabled.


Jira Ticket

RUN-3409Ansible Model Sources return host vars data in key=value format when "Gather Facts" is set to "no"

@edbaltra edbaltra added this to the 5.13.0 milestone May 24, 2025
@edbaltra edbaltra marked this pull request as ready for review May 26, 2025 13:32
@edbaltra edbaltra requested a review from Copilot May 26, 2025 13:33
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances how structured host variables (e.g., lists/maps) are stored when gather_facts is disabled by serializing them as JSON rather than using toString().

  • Adds SLF4J Logger (though a Lombok @Slf4j logger already exists)
  • Introduces on-the-fly Gson instantiation in createNodeEntry
  • Wraps attribute setting to handle Map/List via Gson.toJson()
Comments suppressed due to low confidence (2)

src/main/groovy/com/rundeck/plugins/ansible/plugin/AnsibleResourceModelSource.java:809

  • There are no tests verifying that Map/List values are correctly serialized to JSON and stored in attributes. Adding a unit test for createNodeEntry with structured data would help prevent regressions.
nodeValues.forEach((key, value) -> {

src/main/groovy/com/rundeck/plugins/ansible/plugin/AnsibleResourceModelSource.java:73

  • The class is already annotated with Lombok’s @slf4j, which provides a 'log' instance. Consider removing this redundant 'logger' field to avoid confusion and duplicate loggers.
private static final Logger logger = LoggerFactory.getLogger(AnsibleResourceModelSource.class);

edbaltra and others added 4 commits May 26, 2025 09:35
…urceModelSource.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…-key-value-format-when-Gather-Facts-is-set-to-no' of github.com:rundeck-plugins/ansible-plugin into RUN-3409-Ansible-Model-Sources-return-host-vars-data-in-key-value-format-when-Gather-Facts-is-set-to-no
@Jesus-Osuna-M Jesus-Osuna-M self-requested a review May 28, 2025 14:35
@edbaltra edbaltra merged commit 8e4cd30 into main May 29, 2025
3 checks passed
@fdevans fdevans changed the title Run 3409 ansible model sources return host vars data in key value format when gather facts is set to no Run-3409: Ansible model sources return host vars data in key value format when gather facts is set to no Jul 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants