Skip to content

Commit

Permalink
include_role: Strictly check string datatype for *_from (ansible#68958)
Browse files Browse the repository at this point in the history
Strictly check string datatype for 'tasks_from', 'vars_from',
'defaults_from', and 'handlers_from' in include_role

Fixes: ansible#68515

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
  • Loading branch information
Akasurde authored and bcoca committed Apr 28, 2020
1 parent 512667e commit cc85145
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/68515_include_role_vars_from.yml
@@ -0,0 +1,2 @@
bugfixes:
- Strictly check string datatype for 'tasks_from', 'vars_from', 'defaults_from', and 'handlers_from' in include_role (https://github.com/ansible/ansible/issues/68515).
6 changes: 5 additions & 1 deletion lib/ansible/playbook/role_include.py
Expand Up @@ -27,6 +27,7 @@
from ansible.playbook.role import Role
from ansible.playbook.role.include import RoleInclude
from ansible.utils.display import Display
from ansible.module_utils.six import string_types

__all__ = ['IncludeRole']

Expand Down Expand Up @@ -137,7 +138,10 @@ def load(data, block=None, role=None, task_include=None, variable_manager=None,
# build options for role includes
for key in my_arg_names.intersection(IncludeRole.FROM_ARGS):
from_key = key.replace('_from', '')
ir._from_files[from_key] = basename(ir.args.get(key))
args_value = ir.args.get(key)
if not isinstance(args_value, string_types):
raise AnsibleParserError('Expected a string for %s but got %s instead' % (key, type(args_value)))
ir._from_files[from_key] = basename(args_value)

apply_attrs = ir.args.get('apply', {})
if apply_attrs and ir.action != 'include_role':
Expand Down
Expand Up @@ -153,13 +153,13 @@
include_role:
name: "{{ host_var_role_name }}"

- name: assert that host varible for role name calls 2 diff roles
- name: assert that host variable for role name calls 2 diff roles
assert:
that:
- _role2_result is not none
when: inventory_hostname == 'testhost2'

- name: assert that host varible for role name calls 2 diff roles
- name: assert that host variable for role name calls 2 diff roles
assert:
that:
- _role3_result is not none
Expand Down
@@ -0,0 +1,10 @@
- name: Test include_role vars_from
hosts: testhost
vars:
role_name: role1
tasks:
- name: Test vars_from
include_role:
name: role1
vars_from:
- vars_1.yml
3 changes: 3 additions & 0 deletions test/integration/targets/include_import/runme.sh
Expand Up @@ -42,6 +42,9 @@ ANSIBLE_STRATEGY='free' ansible-playbook tasks/test_include_tasks_tags.yml -i in
ANSIBLE_STRATEGY='linear' ansible-playbook role/test_include_role.yml -i inventory "$@"
ANSIBLE_STRATEGY='free' ansible-playbook role/test_include_role.yml -i inventory "$@"

# https://github.com/ansible/ansible/issues/68515
ansible-playbook -v role/test_include_role_vars_from.yml 2>&1 | tee test_include_role_vars_from.out
test "$(grep -E -c 'Expected a string for vars_from but got' test_include_role_vars_from.out)" = 1

## Max Recursion Depth
# https://github.com/ansible/ansible/issues/23609
Expand Down

0 comments on commit cc85145

Please sign in to comment.