Add check flag to ansible function arguments

This commit is contained in:
Mark Goddard 2017-07-05 19:01:42 +01:00
parent 9a7fae1973
commit 1577ab3c5e
3 changed files with 9 additions and 6 deletions

View File

@ -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:

View File

@ -19,7 +19,6 @@ import subprocess
import sys
from kayobe import utils
from kayobe import vault
DEFAULT_CONFIG_PATH = "/etc/kolla"

View File

@ -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([