summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsommersoft <sommersoft@users.noreply.github.com>2021-03-17 18:52:51 +0100
committerGitHub <noreply@github.com>2021-03-17 18:52:51 +0100
commit4add72310764d1f64a6a60eef89c72736f1528c5 (patch)
tree5fb868cbb9072aa9ecfb913e7c76727483e95b58
parentAdd porting guide for ansible 4 (diff)
downloadansible-4add72310764d1f64a6a60eef89c72736f1528c5.tar.xz
ansible-4add72310764d1f64a6a60eef89c72736f1528c5.zip
ansible-pull: Run All Playbooks When Multiple Are Supplied (#73172)
* ansible-pull: run all playbooks when multiple are supplied * add test for ansible-pull with multiple playbooks supplied from cli * add changelog fragment
-rw-r--r--changelogs/fragments/72708_ansible_pull_multiple_playbooks.yml2
-rw-r--r--lib/ansible/cli/pull.py19
-rw-r--r--test/integration/targets/pull/pull-integration-test/multi_play_1.yml6
-rw-r--r--test/integration/targets/pull/pull-integration-test/multi_play_2.yml6
-rwxr-xr-xtest/integration/targets/pull/runme.sh18
5 files changed, 45 insertions, 6 deletions
diff --git a/changelogs/fragments/72708_ansible_pull_multiple_playbooks.yml b/changelogs/fragments/72708_ansible_pull_multiple_playbooks.yml
new file mode 100644
index 0000000000..14a155937a
--- /dev/null
+++ b/changelogs/fragments/72708_ansible_pull_multiple_playbooks.yml
@@ -0,0 +1,2 @@
+bugfixes:
+- ansible-pull - Run all playbooks that when multiple are supplied via the command line (https://github.com/ansible/ansible/issues/72708) \ No newline at end of file
diff --git a/lib/ansible/cli/pull.py b/lib/ansible/cli/pull.py
index 55b5a2b0fd..e3a3d43565 100644
--- a/lib/ansible/cli/pull.py
+++ b/lib/ansible/cli/pull.py
@@ -311,19 +311,26 @@ class PullCLI(CLI):
@staticmethod
def select_playbook(path):
playbook = None
+ errors = []
if context.CLIARGS['args'] and context.CLIARGS['args'][0] is not None:
- playbook = os.path.join(path, context.CLIARGS['args'][0])
- rc = PullCLI.try_playbook(playbook)
- if rc != 0:
- display.warning("%s: %s" % (playbook, PullCLI.PLAYBOOK_ERRORS[rc]))
- return None
+ playbooks = []
+ for book in context.CLIARGS['args']:
+ book_path = os.path.join(path, book)
+ rc = PullCLI.try_playbook(book_path)
+ if rc != 0:
+ errors.append("%s: %s" % (book_path, PullCLI.PLAYBOOK_ERRORS[rc]))
+ continue
+ playbooks.append(book_path)
+ if 0 < len(errors):
+ display.warning("\n".join(errors))
+ elif len(playbooks) == len(context.CLIARGS['args']):
+ playbook = " ".join(playbooks)
return playbook
else:
fqdn = socket.getfqdn()
hostpb = os.path.join(path, fqdn + '.yml')
shorthostpb = os.path.join(path, fqdn.split('.')[0] + '.yml')
localpb = os.path.join(path, PullCLI.DEFAULT_PLAYBOOK)
- errors = []
for pb in [hostpb, shorthostpb, localpb]:
rc = PullCLI.try_playbook(pb)
if rc == 0:
diff --git a/test/integration/targets/pull/pull-integration-test/multi_play_1.yml b/test/integration/targets/pull/pull-integration-test/multi_play_1.yml
new file mode 100644
index 0000000000..0ec0da6b6d
--- /dev/null
+++ b/test/integration/targets/pull/pull-integration-test/multi_play_1.yml
@@ -0,0 +1,6 @@
+- name: test multiple playbooks for ansible-pull
+ hosts: all
+ gather_facts: False
+ tasks:
+ - name: debug output
+ debug: msg="test multi_play_1"
diff --git a/test/integration/targets/pull/pull-integration-test/multi_play_2.yml b/test/integration/targets/pull/pull-integration-test/multi_play_2.yml
new file mode 100644
index 0000000000..1fe5a58433
--- /dev/null
+++ b/test/integration/targets/pull/pull-integration-test/multi_play_2.yml
@@ -0,0 +1,6 @@
+- name: test multiple playbooks for ansible-pull
+ hosts: all
+ gather_facts: False
+ tasks:
+ - name: debug output
+ debug: msg="test multi_play_2"
diff --git a/test/integration/targets/pull/runme.sh b/test/integration/targets/pull/runme.sh
index dcadc495e8..347971a4fd 100755
--- a/test/integration/targets/pull/runme.sh
+++ b/test/integration/targets/pull/runme.sh
@@ -49,6 +49,20 @@ function pass_tests {
fi
}
+function pass_tests_multi {
+ # test for https://github.com/ansible/ansible/issues/72708
+ if ! grep 'test multi_play_1' "${temp_log}"; then
+ cat "${temp_log}"
+ echo "Did not run multiple playbooks"
+ exit 1
+ fi
+ if ! grep 'test multi_play_2' "${temp_log}"; then
+ cat "${temp_log}"
+ echo "Did not run multiple playbooks"
+ exit 1
+ fi
+}
+
export ANSIBLE_INVENTORY
export ANSIBLE_HOST_PATTERN_MISMATCH
@@ -67,3 +81,7 @@ JSON_EXTRA_ARGS='{"docker_registries_login": [{ "docker_password": "'"${PASSWORD
ANSIBLE_CONFIG='' ansible-pull -d "${pull_dir}" -U "${repo_dir}" -e "${JSON_EXTRA_ARGS}" "$@" --tags untagged,test_ev | tee "${temp_log}"
pass_tests
+
+ANSIBLE_CONFIG='' ansible-pull -d "${pull_dir}" -U "${repo_dir}" "$@" multi_play_1.yml multi_play_2.yml | tee "${temp_log}"
+
+pass_tests_multi \ No newline at end of file