Skip to content

Conversation

@bnerickson
Copy link
Contributor

@bnerickson bnerickson commented Mar 31, 2025

Overview of Changes

This PR intends to add the Ansible Diff Mode (identified with the --diff argument to ansible-runner) to Ansible Job Templates via a checkbox option. This is a follow-on to the changes made to support Ansible Check Mode in https://projects.theforeman.org/issues/37942. Ansible Diff Mode reports changes Ansible tasks make only if the module supports Ansible Diff Mode. Otherwise, the task reports a change has been made with no further details. Note that when used in conjunction with Ansible Check Mode, tasks report changes they would have made without making those changes. Ansible Check Mode and Ansible Diff Mode are not dependent on one-another and can be run independently. Refer to https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_checkmode.html#using-diff-mode for more details about Ansible Diff Mode. See below screenshot for UI update:

diff_mode_1

Implementation Considerations

As suggested in #742, it would be beneficial to have this sort of capability at the job level. I may tackle that next.

Testing Steps

  1. Add the changes in Fixes #38335 - Add job_diff_mode to allow Ansible Check Mode in Job Templates smart_proxy_ansible#100 to your test environment.
  2. Add the changes in this PR to your test environment.
  3. Clone the "Ansible Roles - Ansible Default" Job Template.
  4. In the clone's "Ansible" tab, select the "Ansible Diff Mode Enabled" checkbox and save the Job Template.
  5. In the user-defined Ansible Playbook for the test host, add a "copy" task that changes or deploys a text file with dummy content to the test host in the /tmp directory. For examples:
  - name: Deploy test file
    copy:
      src: "/etc/ansible/roles/somefile"
      dest: "/tmp/somefile"
      owner: root
      group: root
      mode: 0644
  1. Schedule a Job for the test host and select the cloned Job Category and Job Template. Execute the job, and verify in the job's "template_invocation" page that the dummy contents of the file are displayed when the file is changed/deployed.

Checklists

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

Additional Notes

This PR is not dependent on any other changes. The follow PRs are dependent on this change:

@bnerickson
Copy link
Contributor Author

I noticed #749 has been submitted to add diff mode as a host parameter. Just like my previous check mode PR (#742), the functionality added here is for job templates and is independent of and should not conflict with the host parameter changes proposed in #749.

@nofaralfasi
Copy link
Contributor

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

@maximiliankolb
Copy link
Contributor

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

Comment on lines 35 to +37
:check_mode => host.host_param('ansible_roles_check_mode'),
:job_check_mode => template_invocation.template.ansible_check_mode,
:job_diff_mode => template_invocation.template.ansible_diff_mode,
Copy link
Member

@ofedoren ofedoren Jul 22, 2025

Choose a reason for hiding this comment

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

Just looking at the pattern here: don't we need to add diff_mode here as well?.. Nervermind, I found it in another PR.

@bnerickson
Copy link
Contributor Author

Hi @nofaralfasi , I see this PR is approved. Is there anything pending before this PR may be merged?

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.

4 participants