diff --git a/changelogs/fragments/76353-fix-check-mode-skipping.yaml b/changelogs/fragments/76353-fix-check-mode-skipping.yaml new file mode 100644 index 00000000000..6b93fa8f6a9 --- /dev/null +++ b/changelogs/fragments/76353-fix-check-mode-skipping.yaml @@ -0,0 +1,3 @@ +bugfixes: + - shell/command - only skip in check mode if the options `creates` and `removes` are both None. + - script - skip in check mode since the plugin cannot determine if a change will occur. diff --git a/lib/ansible/modules/command.py b/lib/ansible/modules/command.py index cb29b10728a..1e0ff2f615d 100644 --- a/lib/ansible/modules/command.py +++ b/lib/ansible/modules/command.py @@ -373,7 +373,8 @@ def main(): # this is partial check_mode support, since we end up skipping if we get here r['rc'] = 0 r['msg'] = "Command would have run if not in check mode" - r['skipped'] = True + if creates is None and removes is None: + r['skipped'] = True r['changed'] = True diff --git a/lib/ansible/plugins/action/script.py b/lib/ansible/plugins/action/script.py index ad73be88f4b..ff7f2f3a76d 100644 --- a/lib/ansible/plugins/action/script.py +++ b/lib/ansible/plugins/action/script.py @@ -119,7 +119,9 @@ class ActionModule(ActionBase): script_cmd = ' '.join([env_string, target_command]) if self._play_context.check_mode: - raise _AnsibleActionDone() + # If the script doesn't return changed in the result, it defaults to True, + # but since the script may override 'changed', just skip instead of guessing. + raise AnsibleActionSkip('Check mode is not supported for this task.') script_cmd = self._connection._shell.wrap_for_exec(script_cmd)