Raise Warning when import_playbook receives additional parameters (#64156)

* Extra whitespace around imported playbook filename are stripped.
* Corrected call for display.deprecated
* Changed warning type & added test
* Added auto verification of raised warning
* More accurate warning message
This commit is contained in:
Kshitij Chawla 2020-06-10 19:22:40 +02:00 committed by GitHub
parent ac20466375
commit 32c392e622
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 3 deletions

View file

@ -30,6 +30,9 @@ from ansible.playbook.base import Base
from ansible.playbook.conditional import Conditional
from ansible.playbook.taggable import Taggable
from ansible.template import Templar
from ansible.utils.display import Display
display = Display()
class PlaybookInclude(Base, Conditional, Taggable):
@ -144,8 +147,9 @@ class PlaybookInclude(Base, Conditional, Taggable):
if len(items) == 0:
raise AnsibleParserError("import_playbook statements must specify the file name to import", obj=ds)
else:
new_ds['import_playbook'] = items[0]
new_ds['import_playbook'] = items[0].strip()
if len(items) > 1:
display.warning('Additional parameters in import_playbook statements are not supported. This will be an error in version 2.14')
# rejoin the parameter portion of the arguments and
# then use parse_kv() to get a dict of params back
params = parse_kv(" ".join(items[1:]))

View file

@ -1,3 +1,6 @@
# Test that additional parameters after import_playbook raises a warning & strips whitespaces
- import_playbook: playbook1.yml tags=test_import
# Test and validate playbook import
- import_playbook: playbook1.yml
- import_playbook: validate1.yml

View file

@ -17,8 +17,8 @@ ansible -m include_role -a name=role1 localhost
## Import (static)
# Playbook
ANSIBLE_STRATEGY='linear' ansible-playbook playbook/test_import_playbook.yml -i inventory "$@"
ANSIBLE_STRATEGY='free' ansible-playbook playbook/test_import_playbook.yml -i inventory "$@"
test "$(ansible-playbook -i ../../inventory playbook/test_import_playbook.yml "$@" 2>&1 | grep -c '\[WARNING\]: Additional parameters in import_playbook')" = 1
ANSIBLE_STRATEGY='linear' ansible-playbook playbook/test_import_playbook_tags.yml -i inventory "$@" --tags canary1,canary22,validate --skip-tags skipme
# Tasks