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
This commit is contained in:
sommersoft 2021-03-17 12:52:51 -05:00 committed by GitHub
parent 0279d02980
commit 4add723107
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 6 deletions

View file

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

View file

@ -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)
playbooks = []
for book in context.CLIARGS['args']:
book_path = os.path.join(path, book)
rc = PullCLI.try_playbook(book_path)
if rc != 0:
display.warning("%s: %s" % (playbook, PullCLI.PLAYBOOK_ERRORS[rc]))
return None
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:

View file

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

View file

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

View file

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