Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow --check and be less strict about --diff #6128

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/commcare_cloud/commands/ansible/ansible_playbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()

Expand All @@ -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)


Expand Down
Loading