diff --git a/kayobe/ansible.py b/kayobe/ansible.py index 1318b180c..7e72c9c01 100644 --- a/kayobe/ansible.py +++ b/kayobe/ansible.py @@ -104,7 +104,8 @@ def _get_vars_files(config_path): def build_args(parsed_args, playbooks, - extra_vars=None, limit=None, tags=None, verbose_level=None): + extra_vars=None, limit=None, tags=None, verbose_level=None, + check=None): """Build arguments required for running Ansible playbooks.""" cmd = ["ansible-playbook"] if verbose_level: @@ -123,7 +124,7 @@ def build_args(parsed_args, playbooks, cmd += ["-e", "%s=%s" % (extra_var_name, extra_var_value)] if parsed_args.become: cmd += ["--become"] - if parsed_args.check: + if check or (parsed_args.check and check is None): cmd += ["--check"] if parsed_args.limit or limit: limits = [l for l in [parsed_args.limit, limit] if l] @@ -137,12 +138,12 @@ def build_args(parsed_args, playbooks, def run_playbooks(parsed_args, playbooks, extra_vars=None, limit=None, tags=None, quiet=False, - verbose_level=None): + verbose_level=None, check=None): """Run a Kayobe Ansible playbook.""" _validate_args(parsed_args, playbooks) cmd = build_args(parsed_args, playbooks, extra_vars=extra_vars, limit=limit, tags=tags, - verbose_level=verbose_level) + verbose_level=verbose_level, check=check) try: utils.run_command(cmd, quiet=quiet) except subprocess.CalledProcessError as e: diff --git a/kayobe/kolla_ansible.py b/kayobe/kolla_ansible.py index 4600a6fdd..7729b5453 100644 --- a/kayobe/kolla_ansible.py +++ b/kayobe/kolla_ansible.py @@ -19,7 +19,6 @@ import subprocess import sys from kayobe import utils -from kayobe import vault DEFAULT_CONFIG_PATH = "/etc/kolla" diff --git a/kayobe/tests/unit/test_ansible.py b/kayobe/tests/unit/test_ansible.py index c4a8b2529..c379ac4e1 100644 --- a/kayobe/tests/unit/test_ansible.py +++ b/kayobe/tests/unit/test_ansible.py @@ -207,6 +207,7 @@ class TestCase(unittest.TestCase): "limit": "group2:host2", "tags": "tag3,tag4", "verbose_level": 0, + "check": True, } ansible.run_playbooks(parsed_args, ["playbook1.yml", "playbook2.yml"], **kwargs) @@ -217,6 +218,7 @@ class TestCase(unittest.TestCase): "-e", "@/etc/kayobe/vars-file2.yaml", "-e", "ev_name1=ev_value1", "-e", "ev_name2=ev_value2", + "--check", "--limit", "group1:host1:&group2:host2", "--tags", "tag1,tag2,tag3,tag4", "playbook1.yml", @@ -263,7 +265,8 @@ class TestCase(unittest.TestCase): extra_vars={ "dump_path": dump_dir, }, - quiet=True, verbose_level=None) + quiet=True, verbose_level=None, + check=False) mock_rmtree.assert_called_once_with(dump_dir) mock_listdir.assert_called_once_with(dump_dir) mock_read.assert_has_calls([