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:
parent
ac20466375
commit
32c392e622
3 changed files with 10 additions and 3 deletions
|
@ -30,6 +30,9 @@ from ansible.playbook.base import Base
|
||||||
from ansible.playbook.conditional import Conditional
|
from ansible.playbook.conditional import Conditional
|
||||||
from ansible.playbook.taggable import Taggable
|
from ansible.playbook.taggable import Taggable
|
||||||
from ansible.template import Templar
|
from ansible.template import Templar
|
||||||
|
from ansible.utils.display import Display
|
||||||
|
|
||||||
|
display = Display()
|
||||||
|
|
||||||
|
|
||||||
class PlaybookInclude(Base, Conditional, Taggable):
|
class PlaybookInclude(Base, Conditional, Taggable):
|
||||||
|
@ -144,8 +147,9 @@ class PlaybookInclude(Base, Conditional, Taggable):
|
||||||
if len(items) == 0:
|
if len(items) == 0:
|
||||||
raise AnsibleParserError("import_playbook statements must specify the file name to import", obj=ds)
|
raise AnsibleParserError("import_playbook statements must specify the file name to import", obj=ds)
|
||||||
else:
|
else:
|
||||||
new_ds['import_playbook'] = items[0]
|
new_ds['import_playbook'] = items[0].strip()
|
||||||
if len(items) > 1:
|
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
|
# rejoin the parameter portion of the arguments and
|
||||||
# then use parse_kv() to get a dict of params back
|
# then use parse_kv() to get a dict of params back
|
||||||
params = parse_kv(" ".join(items[1:]))
|
params = parse_kv(" ".join(items[1:]))
|
||||||
|
|
|
@ -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
|
# Test and validate playbook import
|
||||||
- import_playbook: playbook1.yml
|
- import_playbook: playbook1.yml
|
||||||
- import_playbook: validate1.yml
|
- import_playbook: validate1.yml
|
||||||
|
|
|
@ -17,8 +17,8 @@ ansible -m include_role -a name=role1 localhost
|
||||||
## Import (static)
|
## Import (static)
|
||||||
|
|
||||||
# Playbook
|
# Playbook
|
||||||
ANSIBLE_STRATEGY='linear' 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='free' ansible-playbook playbook/test_import_playbook.yml -i inventory "$@"
|
|
||||||
ANSIBLE_STRATEGY='linear' ansible-playbook playbook/test_import_playbook_tags.yml -i inventory "$@" --tags canary1,canary22,validate --skip-tags skipme
|
ANSIBLE_STRATEGY='linear' ansible-playbook playbook/test_import_playbook_tags.yml -i inventory "$@" --tags canary1,canary22,validate --skip-tags skipme
|
||||||
|
|
||||||
# Tasks
|
# Tasks
|
||||||
|
|
Loading…
Reference in a new issue