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

ansible-pull: Run All Playbooks When Multiple Are Supplied #73172

Merged
merged 3 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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)
19 changes: 13 additions & 6 deletions lib/ansible/cli/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,19 +311,26 @@ def try_playbook(path):
@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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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"
18 changes: 18 additions & 0 deletions test/integration/targets/pull/runme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

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