Skip to content

Conversation

@rpluem-vf
Copy link

@rpluem-vf rpluem-vf commented Jan 24, 2025

Overview of Changes

  • Add the parameter ansible_roles_diff_mode to enable Ansible diff mode. Furthermore add the needed functionality to the reports helper to show these diffs in reports.

Implementation Considerations

  • What factors or considerations were taken into account while implementing this change?

Testing Steps

  • Have an Ansible role imported into Foreman that changes a file e.g. via a template, copy or lineinfile task and set the ansible_roles_diff_mode parameter to true for this host. Run the Ansible Ansible Roles - Ansible Default job. Afterwards the diff of the change can been seen in the script output and in the config report via a link. This requires all three PR's.

Checklists

  • I am familiar with the contributing guidelines.
  • I have added relevant tests for my changes.
  • I have updated the documentation accordingly.

Additional Notes

Depends on the following PR's:

@rpluem-vf
Copy link
Author

Any update?

@bnerickson
Copy link
Contributor

Hello @rpluem-vf

Just so you're aware I've submitted #764 to add diff mode support to Job Templates.

@nofaralfasi
Copy link
Contributor

nofaralfasi commented Apr 22, 2025

Any update?

Hi, it may take some time before we're able to start reviewing this PR. Thank you for your patience and understanding.

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

Overall I think this reads well. I haven't tested it myself yet. Some minor notes inline.

Just a general note that all the translations in this helper are broken (because you can't interpolate strings this way), but they already were before you came in.

Comment on lines 64 to 70
have_diff = false
get_results(msg_json) do |_, result|
if result['report_diff'].present?
have_diff = true
break
end
end
if have_diff
get_results(msg_json) do |module_args, result|
add_diff('', module_args['path'] || '', result) if result['report_diff'].present?
end
else
no_data_message
end
Copy link
Member

Choose a reason for hiding this comment

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

Can't you merge these 2 together into a single loop?

Copy link
Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

Choose a reason for hiding this comment

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

I don't see the change. I expected a single get_results call

Copy link
Author

Choose a reason for hiding this comment

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

My bad. I did not add this to the commit. Should be there now.

@rpluem-vf
Copy link
Author

@rpluem-vf
Copy link
Author

Added the suggestion based on the rubocop output, rebased and squashed the commits.

@rpluem-vf
Copy link
Author

@ekohl Can you please approve the workflows such that we can move on?

@rpluem-vf rpluem-vf requested a review from ekohl July 8, 2025 07:32
@maximiliankolb
Copy link
Contributor

docs triage: @nofaralfasi Could you please review this PR?

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

The code looks good to me, though I haven't found the time to actually test this out myself. One minor note inline.

…sible diff mode

Add the parameter ansible_roles_diff_mode to enable Ansible diff mode.
Furthermore add the needed functionality to the reports helper to
show these diffs in reports.

* app/helpers/foreman_ansible/ansible_reports_helper.rb:
  Check if the result hash of a task contains a 'report_diff' key
  and make its value, the unified diff, available via a link.

* app/models/foreman_ansible/ansible_provider.rb:
  Set the diff_mode smart proxy parameter based on the parameter
  ansible_roles_diff_mode.

* db/seeds.d/100_common_parameters.rb:
  Create the global parameter ansible_roles_diff_mode with a default
  of false.

* test/fixtures/report.json:
  Add fixture data for new test case

* test/unit/helpers/ansible_reports_helper_test.rb:
  - Adjust expected strings existing test cases
  - Add new test case for diff_mode
  - Include further modules used by ansible_reports_helper.rb

Signed-off-by: Ruediger Pluem <[email protected]>

Improve hash lookup in app/helpers/foreman_ansible/ansible_reports_helper.rb

Co-authored-by: Ewoud Kohl van Wijngaarden <[email protected]>

Fix rubocop errors in app/helpers/foreman_ansible/ansible_reports_helper.rb

Co-authored-by: Ewoud Kohl van Wijngaarden <[email protected]>

Add trailing space to translated message

Co-authored-by: Ewoud Kohl van Wijngaarden <[email protected]>
@rpluem-vf
Copy link
Author

Now the workflows wait for approval again

@maximiliankolb
Copy link
Contributor

@adamruzicka Please run the GHA.

@rpluem-vf
Copy link
Author

Is there anything that could be done to move this forward?

@rpluem-vf
Copy link
Author

@ekohl : Any update on this PR?

@rpluem-vf
Copy link
Author

Any update on this PR?

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.

5 participants