Add the ability to call --list-tasks
This allows you to print out which tasks will be executed, without actually running the tasks. It could help debug using the tag and filtering features. When developing, it makes the feedback loop quicker because non of the tasks need to execute. Note this doesn't work for kolla-ansible, as their CLI doesn't support this command line. Which frankly makes this a little useless, but we could always push that upstream if it proves handy.
This commit is contained in:
parent
a97c41b2f4
commit
f638616818
@ -58,6 +58,10 @@ def add_args(parser):
|
|||||||
parser.add_argument("-t", "--tags", metavar="TAGS",
|
parser.add_argument("-t", "--tags", metavar="TAGS",
|
||||||
help="only run plays and tasks tagged with these "
|
help="only run plays and tasks tagged with these "
|
||||||
"values")
|
"values")
|
||||||
|
parser.add_argument("-lt", "--list-tasks",
|
||||||
|
action="store_true",
|
||||||
|
help="only print names of tasks, don't run them, "
|
||||||
|
"note this has no affect on kolla-ansible.")
|
||||||
|
|
||||||
|
|
||||||
def _get_inventory_path(parsed_args):
|
def _get_inventory_path(parsed_args):
|
||||||
@ -110,6 +114,8 @@ def build_args(parsed_args, playbooks,
|
|||||||
cmd = ["ansible-playbook"]
|
cmd = ["ansible-playbook"]
|
||||||
if verbose_level:
|
if verbose_level:
|
||||||
cmd += ["-" + "v" * verbose_level]
|
cmd += ["-" + "v" * verbose_level]
|
||||||
|
if parsed_args.list_tasks:
|
||||||
|
cmd += ["--list-tasks"]
|
||||||
cmd += vault.build_args(parsed_args)
|
cmd += vault.build_args(parsed_args)
|
||||||
inventory = _get_inventory_path(parsed_args)
|
inventory = _get_inventory_path(parsed_args)
|
||||||
cmd += ["--inventory", inventory]
|
cmd += ["--inventory", inventory]
|
||||||
|
@ -68,11 +68,17 @@ class TestCase(unittest.TestCase):
|
|||||||
"-i", "/path/to/inventory",
|
"-i", "/path/to/inventory",
|
||||||
"-l", "group1:host",
|
"-l", "group1:host",
|
||||||
"-t", "tag1,tag2",
|
"-t", "tag1,tag2",
|
||||||
|
"-lt",
|
||||||
]
|
]
|
||||||
parsed_args = parser.parse_args(args)
|
parsed_args = parser.parse_args(args)
|
||||||
ansible.run_playbooks(parsed_args, ["playbook1.yml", "playbook2.yml"])
|
ansible.run_playbooks(
|
||||||
|
parsed_args,
|
||||||
|
["playbook1.yml", "playbook2.yml"],
|
||||||
|
verbose_level=2)
|
||||||
expected_cmd = [
|
expected_cmd = [
|
||||||
"ansible-playbook",
|
"ansible-playbook",
|
||||||
|
"-vv",
|
||||||
|
"--list-tasks",
|
||||||
"--inventory", "/path/to/inventory",
|
"--inventory", "/path/to/inventory",
|
||||||
"-e", "@/path/to/config/vars-file1.yml",
|
"-e", "@/path/to/config/vars-file1.yml",
|
||||||
"-e", "@/path/to/config/vars-file2.yaml",
|
"-e", "@/path/to/config/vars-file2.yaml",
|
||||||
@ -106,11 +112,13 @@ class TestCase(unittest.TestCase):
|
|||||||
"--inventory", "/path/to/inventory",
|
"--inventory", "/path/to/inventory",
|
||||||
"--limit", "group1:host1",
|
"--limit", "group1:host1",
|
||||||
"--tags", "tag1,tag2",
|
"--tags", "tag1,tag2",
|
||||||
|
"--list-tasks",
|
||||||
]
|
]
|
||||||
parsed_args = parser.parse_args(args)
|
parsed_args = parser.parse_args(args)
|
||||||
ansible.run_playbooks(parsed_args, ["playbook1.yml", "playbook2.yml"])
|
ansible.run_playbooks(parsed_args, ["playbook1.yml", "playbook2.yml"])
|
||||||
expected_cmd = [
|
expected_cmd = [
|
||||||
"ansible-playbook",
|
"ansible-playbook",
|
||||||
|
"--list-tasks",
|
||||||
"--ask-vault-pass",
|
"--ask-vault-pass",
|
||||||
"--inventory", "/path/to/inventory",
|
"--inventory", "/path/to/inventory",
|
||||||
"-e", "@/path/to/config/vars-file1.yml",
|
"-e", "@/path/to/config/vars-file1.yml",
|
||||||
|
Loading…
Reference in New Issue
Block a user