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:
parent
0279d02980
commit
4add723107
5 changed files with 45 additions and 6 deletions
|
@ -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)
|
|
@ -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:
|
||||
|
|
|
@ -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"
|
|
@ -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"
|
|
@ -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
|
Loading…
Reference in a new issue