From 70ffa92c80cc819956117d4bc0299c3bfcbaea16 Mon Sep 17 00:00:00 2001 From: Daniel Miller Date: Mon, 18 Sep 2023 09:17:40 -0400 Subject: [PATCH] Allow --check and be less strict about --diff It's confusing to get a "that option is managed automatically" error when attempting to run with --check. The operator is forced to guess what will happen when lacking a thorough understanding of how the automatic option management works. It seems appropriate to perform a single --check run if that was requested by the operator. The situation is similar for --diff, although a duplicate option does not cause harm and does not change the run mode. --- .../commands/ansible/ansible_playbook.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/commcare_cloud/commands/ansible/ansible_playbook.py b/src/commcare_cloud/commands/ansible/ansible_playbook.py index a1f87f2732..f00d35f1c9 100644 --- a/src/commcare_cloud/commands/ansible/ansible_playbook.py +++ b/src/commcare_cloud/commands/ansible/ansible_playbook.py @@ -15,7 +15,7 @@ from commcare_cloud.alias import commcare_cloud from commcare_cloud.cli_utils import ask, has_arg, check_branch, print_command, has_local_connection_arg from commcare_cloud.user_utils import get_dev_username -from commcare_cloud.colors import color_error, color_notice, color_code +from commcare_cloud.colors import color_error, color_warning, color_notice, color_code from commcare_cloud.commands import shared_args from commcare_cloud.commands.ansible.helpers import ( AnsibleContext, DEPRECATED_ANSIBLE_ARGS, @@ -141,12 +141,9 @@ def ansible_playbook(playbook, *cmd_args): env_vars = ansible_context.build_env() cmd_parts += get_user_arg(public_vars, unknown_args, use_factory_auth) - if has_arg(unknown_args, '-D', '--diff') or has_arg(unknown_args, '-C', '--check'): - puts(color_error("Options --diff and --check not allowed. " - "Please remove -D, --diff, -C, --check.")) - puts(color_error("These ansible-playbook options are managed automatically " - "by commcare-cloud and cannot be set manually.")) - return 2 # exit code + if has_arg(unknown_args, '-D', '--diff'): + puts(color_warning("WARNING: Redundant --diff option.")) + puts(color_warning("This ansible-playbook option is managed automatically by commcare-cloud.")) cmd_parts += environment.secrets_backend.get_extra_ansible_args() @@ -167,6 +164,11 @@ def run_check(): def run_apply(): return ansible_playbook(playbook, *unknown_args) + if has_arg(unknown_args, '-C', '--check'): + # run once with --check if that arg was specified explicitly + with ansible_context.environment.secrets_backend.suppress_datadog_event(): + return ansible_playbook(playbook, *unknown_args) + return run_action_with_check_mode(run_check, run_apply, skip_check, quiet, always_skip_check)