From 142732dba907c10d6ed6a187d190f6c0b6ec6c86 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Sat, 16 Mar 2019 11:18:01 +0530 Subject: [PATCH] dataloader: check exact value of dir (#52021) Include path in role with directory which has 'tasks' as end. For example, roles/sometasks/templates is now considered while searching path. Fixes: #42585 Signed-off-by: Abhijeet Kasurde --- lib/ansible/parsing/dataloader.py | 8 ++++---- .../targets/template/custom_tasks/tasks/main.yml | 12 ++++++++++++ .../targets/template/custom_tasks/templates/test | 1 + .../integration/targets/template/custom_template.yml | 4 ++++ test/integration/targets/template/runme.sh | 3 +++ 5 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 test/integration/targets/template/custom_tasks/tasks/main.yml create mode 100644 test/integration/targets/template/custom_tasks/templates/test create mode 100644 test/integration/targets/template/custom_template.yml diff --git a/lib/ansible/parsing/dataloader.py b/lib/ansible/parsing/dataloader.py index 3189413bbe9..be61c55a749 100644 --- a/lib/ansible/parsing/dataloader.py +++ b/lib/ansible/parsing/dataloader.py @@ -290,12 +290,12 @@ class DataLoader: for path in paths: upath = unfrackpath(path, follow=False) b_upath = to_bytes(upath, errors='surrogate_or_strict') - b_mydir = os.path.dirname(b_upath) + b_pb_base_dir = os.path.dirname(b_upath) # if path is in role and 'tasks' not there already, add it into the search - if (is_role or self._is_role(path)) and b_mydir.endswith(b'tasks'): - search.append(os.path.join(os.path.dirname(b_mydir), b_dirname, b_source)) - search.append(os.path.join(b_mydir, b_source)) + if (is_role or self._is_role(path)) and b_pb_base_dir.endswith(b'/tasks'): + search.append(os.path.join(os.path.dirname(b_pb_base_dir), b_dirname, b_source)) + search.append(os.path.join(b_pb_base_dir, b_source)) else: # don't add dirname if user already is using it in source if b_source.split(b'/')[0] != dirname: diff --git a/test/integration/targets/template/custom_tasks/tasks/main.yml b/test/integration/targets/template/custom_tasks/tasks/main.yml new file mode 100644 index 00000000000..d9f5e445b8d --- /dev/null +++ b/test/integration/targets/template/custom_tasks/tasks/main.yml @@ -0,0 +1,12 @@ +--- +- template: + src: test + dest: "{{ output_dir }}/templated_test" + register: custom_template_result + +- debug: + msg: "{{ custom_template_result }}" + +- assert: + that: + - custom_template_result.changed diff --git a/test/integration/targets/template/custom_tasks/templates/test b/test/integration/targets/template/custom_tasks/templates/test new file mode 100644 index 00000000000..d033f12552e --- /dev/null +++ b/test/integration/targets/template/custom_tasks/templates/test @@ -0,0 +1 @@ +Sample Text diff --git a/test/integration/targets/template/custom_template.yml b/test/integration/targets/template/custom_template.yml new file mode 100644 index 00000000000..e5c7aac81eb --- /dev/null +++ b/test/integration/targets/template/custom_template.yml @@ -0,0 +1,4 @@ +- hosts: testhost + gather_facts: yes + roles: + - { role: custom_tasks } diff --git a/test/integration/targets/template/runme.sh b/test/integration/targets/template/runme.sh index 4df69c425a0..2b58bc92dd3 100755 --- a/test/integration/targets/template/runme.sh +++ b/test/integration/targets/template/runme.sh @@ -9,3 +9,6 @@ ansible testhost -i testhost, -m debug -a 'msg={{ hostvars["localhost"] }}' -e " # Test for https://github.com/ansible/ansible/issues/27262 ansible-playbook ansible_managed.yml -c ansible_managed.cfg -i ../../inventory -e @../../integration_config.yml -v "$@" + +# Test for #42585 +ANSIBLE_ROLES_PATH=../ ansible-playbook custom_template.yml -i ../../inventory -e @../../integration_config.yml -v "$@"