foreman_ansible
foreman_ansible copied to clipboard
Fixes #37942 - Adding Ansible Check Mode to Ansible Job Templates
Overview of Changes
This PR intends to add the Ansible Check Mode (identified with the --check
argument to ansible-runner) to Ansible Job Templates via a checkbox option. The follow-up after all the subsequent PRs are submitted/approved (hammer cli support for instance) is to add Ansible Diff Mode support in a similar manner. See below screenshot:
Implementation Considerations
Foreman already offers the ability for users to run Ansible Config Commands (Running Ansible Roles on a host) with check mode enabled by setting the host's host parameter ansible_roles_check_mode to True. This is left in-place as-is. However, that implementation does not allow users to run Ansible Playbook jobs or any other custom remote execution jobs in Ansible Check Mode. Nor is setting a host parameter as flexible as setting an entire Job Template to use Ansible Check Mode.
I have a few questions/concerns:
- It's sort of kludgy, but I've added a separate "job_check_mode" variable passed to the smart_proxy_ansible plugin instead of using the existing "check_mode" variable. My reason for doing this is that the latter is used when setting the ansible_roles_check_mode host parameter which is only intended for use when running an Ansible Roles job. Meanwhile, this PR is intended for use on any host that is the target of any job whose template uses the new Ansible Check Mode (identified by the "job_check_mode" variable). Another reason I split the functions in two is that I do not want to break the existing functionality. Because of this change, "check_mode" with the ansible_roles_check_mode parameter will not work for rex (remote execution) jobs. This obviously runs completely counter to what I'm trying to accomplish in this PR.
- For the db/migrate/20241022000000_add_ansible_check_mode_to_templates.rb file, I arbitrarily set the date string in the filename to 20241022000000, but is that supposed to be automatically generated somehow?
Testing Steps
- Add the changes in https://github.com/theforeman/smart_proxy_ansible/pull/94 to your test environment.
- Add the changes in this PR to your test environment.
- Clone the "Ansible Roles - Ansible Default" Job Template.
- In the clone's "Ansible" tab, select the "Ansible Check Mode Enabled" checkbox and save the Job Template.
- On a host, schedule a Job and select the cloned Job Category and Job Template. Execute the job.
Checklists
- [x] I am familiar with the contributing guidelines.
- [x] I have added relevant tests for my changes.
- [x] 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:
- [x] hammer-cli PR: https://github.com/theforeman/hammer-cli-foreman-ansible/pull/31
- [x] smart_proxy_ansible PR: https://github.com/theforeman/smart_proxy_ansible/pull/94
- [x] Documentation update PR: https://github.com/theforeman/foreman-documentation/pull/3391