Issue
Background: --check allows users to run a playbook and see the proposed changes without actually executing them - this is essentially for guarding against accidental destructive configuration updates on critical network infrastructure.
All of the cp_gaia_* modules advertise support for Check Mode (i.e. supports_check_mode=True), however the main checkpoint.py module does not incorporate logic for check_mode and runs the associated /set-* or /add-* API regardless of whether the playbook is run with --check.
Fix
checkpoint.py contains the main API functions utilized by all upstream modules, specifically chkp_api_call and chkp_api_operation.
These functions handle several logical trees for different request types, as well as idempotency flows:
- Value exists and must be removed (i.e.
state=absent)
- Value matches -> no change
- Value does not match -> run update
- Maestro special cases
To support check_mode, the logic in these functions needs to be updated to return early, with a diff, rather than running the /set-* or /add-* command.
# EXAMPLE: object exists and needs to be updated
# object exists and would be modified
if module.check_mode:
after_preview = dict(before)
after_preview.update(params_for_idempotency)
return {
api_call_object.replace('-', '_'): before,
'diff': {'before': before, 'after': after_preview},
"changed": True,
}
Adding diff to the response allows the --diff flag to display the results for the user to view and confirm - this is a very important feature for reviewing changes
I am happy to help contribute a fix for this issue via pull-request.
Thanks!
Issue
Background:
--checkallows users to run a playbook and see the proposed changes without actually executing them - this is essentially for guarding against accidental destructive configuration updates on critical network infrastructure.All of the
cp_gaia_*modules advertise support for Check Mode (i.e. supports_check_mode=True), however the main checkpoint.py module does not incorporate logic forcheck_modeand runs the associated/set-*or/add-*API regardless of whether the playbook is run with--check.Fix
checkpoint.pycontains the main API functions utilized by all upstream modules, specifically chkp_api_call and chkp_api_operation.These functions handle several logical trees for different request types, as well as idempotency flows:
state=absent)To support
check_mode, the logic in these functions needs to be updated to return early, with adiff, rather than running the/set-*or/add-*command.Adding
diffto the response allows the--diffflag to display the results for the user to view and confirm - this is a very important feature for reviewing changesI am happy to help contribute a fix for this issue via pull-request.
Thanks!