Fix regression in search path behaviour
This PR fixes a few issues:
- Missing role parent directory for relative paths
- Fix integration tests (add missing stage)
- Redesign integration tests
- Incorrect order with tasks-lookups
- Duplicate paths are listed
- Repetitive tasks/tasks or files/files were possible
==== using copy with test.txt
Before:
```
491 1481281038.29393: search_path:
/home/dag/home-made/ansible.testing/roles/test134/files/test.txt
/home/dag/home-made/ansible.testing/roles/test134/tasks/test.txt
/home/dag/home-made/ansible.testing/roles/test134/tasks/files/test.txt
/home/dag/home-made/ansible.testing/roles/test134/tasks/tasks/test.txt
/home/dag/home-made/ansible.testing/files/test.txt
/home/dag/home-made/ansible.testing/test.txt
```
After:
```
32505 1481280963.22418: search_path:
/home/dag/home-made/ansible.testing/roles/test134/files/test.txt
/home/dag/home-made/ansible.testing/roles/test134/test.txt
/home/dag/home-made/ansible.testing/roles/test134/tasks/files/test.txt
/home/dag/home-made/ansible.testing/roles/test134/tasks/test.txt
/home/dag/home-made/ansible.testing/files/test.txt
/home/dag/home-made/ansible.testing/test.txt
```
==== Using copy with files/test.txt
Before:
```
31523 1481280499.63052: search_path:
/home/dag/home-made/ansible.testing/roles/test134/files/test.txt
/home/dag/home-made/ansible.testing/roles/test134/tasks/files/test.txt
/home/dag/home-made/ansible.testing/roles/test134/tasks/files/test.txt
/home/dag/home-made/ansible.testing/roles/test134/tasks/tasks/files/test.txt
/home/dag/home-made/ansible.testing/files/files/test.txt
/home/dag/home-made/ansible.testing/files/test.txt
```
After:
```
31110 1481280299.38778: search_path:
/home/dag/home-made/ansible.testing/roles/test134/files/test.txt
/home/dag/home-made/ansible.testing/roles/test134/tasks/files/test.txt
/home/dag/home-made/ansible.testing/files/test.txt
```
==== Using template with files/test.txt.j2
Before:
```
30074 1481280064.15191: search_path:
/home/dag/home-made/ansible.testing/roles/test134/templates/files/test.txt.j2
/home/dag/home-made/ansible.testing/roles/test134/tasks/files/test.txt.j2
/home/dag/home-made/ansible.testing/roles/test134/tasks/templates/files/test.txt.j2
/home/dag/home-made/ansible.testing/roles/test134/tasks/tasks/files/test.txt.j2
/home/dag/home-made/ansible.testing/templates/files/test.txt.j2
/home/dag/home-made/ansible.testing/files/test.txt.j2
```
After:
```
29201 1481279823.52752: search_path:
/home/dag/home-made/ansible.testing/roles/test134/templates/files/test.txt.j2
/home/dag/home-made/ansible.testing/roles/test134/files/test.txt.j2
/home/dag/home-made/ansible.testing/roles/test134/tasks/templates/files/test.txt.j2
/home/dag/home-made/ansible.testing/roles/test134/tasks/files/test.txt.j2
/home/dag/home-made/ansible.testing/templates/files/test.txt.j2
/home/dag/home-made/ansible.testing/files/test.txt.j2
```
This fixes #19048
(cherry picked from commit 7c71c678fa
)
This commit is contained in:
parent
e715221a66
commit
268645c17a
3 changed files with 35 additions and 42 deletions
|
@ -301,6 +301,7 @@ class DataLoader():
|
||||||
result = test_path
|
result = test_path
|
||||||
else:
|
else:
|
||||||
search = []
|
search = []
|
||||||
|
display.debug(u'evaluation_path:\n\t%s' % '\n\t'.join(paths))
|
||||||
for path in paths:
|
for path in paths:
|
||||||
upath = unfrackpath(path)
|
upath = unfrackpath(path)
|
||||||
b_upath = to_bytes(upath, errors='surrogate_or_strict')
|
b_upath = to_bytes(upath, errors='surrogate_or_strict')
|
||||||
|
@ -315,17 +316,19 @@ class DataLoader():
|
||||||
search.append(os.path.join(b_mydir, b_source))
|
search.append(os.path.join(b_mydir, b_source))
|
||||||
else:
|
else:
|
||||||
# don't add dirname if user already is using it in source
|
# don't add dirname if user already is using it in source
|
||||||
if b_source.split(b'/')[0] == b_dirname:
|
if b_source.split(b'/')[0] != b_dirname:
|
||||||
search.append(os.path.join(b_upath, b_source))
|
|
||||||
else:
|
|
||||||
search.append(os.path.join(b_upath, b_dirname, b_source))
|
search.append(os.path.join(b_upath, b_dirname, b_source))
|
||||||
search.append(os.path.join(b_upath, b'tasks', b_source))
|
search.append(os.path.join(b_upath, b_source))
|
||||||
|
|
||||||
elif b_dirname not in b_source.split(b'/'):
|
elif b_dirname not in b_source.split(b'/'):
|
||||||
# don't add dirname if user already is using it in source
|
# don't add dirname if user already is using it in source
|
||||||
|
if b_source.split(b'/')[0] != dirname:
|
||||||
search.append(os.path.join(b_upath, b_dirname, b_source))
|
search.append(os.path.join(b_upath, b_dirname, b_source))
|
||||||
search.append(os.path.join(b_upath, b_source))
|
search.append(os.path.join(b_upath, b_source))
|
||||||
|
|
||||||
# always append basedir as last resort
|
# always append basedir as last resort
|
||||||
|
# don't add dirname if user already is using it in source
|
||||||
|
if b_source.split(b'/')[0] != dirname:
|
||||||
search.append(os.path.join(to_bytes(self.get_basedir()), b_dirname, b_source))
|
search.append(os.path.join(to_bytes(self.get_basedir()), b_dirname, b_source))
|
||||||
search.append(os.path.join(to_bytes(self.get_basedir()), b_source))
|
search.append(os.path.join(to_bytes(self.get_basedir()), b_source))
|
||||||
|
|
||||||
|
|
|
@ -6,53 +6,40 @@
|
||||||
- file: path={{playbook_dir}}/files state=directory
|
- file: path={{playbook_dir}}/files state=directory
|
||||||
- file: path={{playbook_dir}}/roles/showfile/files state=directory
|
- file: path={{playbook_dir}}/roles/showfile/files state=directory
|
||||||
- copy: dest={{playbook_dir}}/roles/showfile/files/testfile content='in role files'
|
- copy: dest={{playbook_dir}}/roles/showfile/files/testfile content='in role files'
|
||||||
- copy: dest={{playbook_dir}}/roles/showfile/tasks/testfile content='in role tasks'
|
|
||||||
- copy: dest={{playbook_dir}}/roles/showfile/testfile content='in role'
|
- copy: dest={{playbook_dir}}/roles/showfile/testfile content='in role'
|
||||||
|
- copy: dest={{playbook_dir}}/roles/showfile/tasks/testfile content='in role tasks'
|
||||||
- copy: dest={{playbook_dir}}/files/testfile content='in files'
|
- copy: dest={{playbook_dir}}/files/testfile content='in files'
|
||||||
- copy: dest={{playbook_dir}}/testfile content='in local'
|
- copy: dest={{playbook_dir}}/testfile content='in local'
|
||||||
- set_fact: role_out="in role files" play_out="in files" stage='setup'
|
|
||||||
|
|
||||||
- include: testplay.yml
|
- include: testplay.yml
|
||||||
|
vars:
|
||||||
- name: remove from role/files
|
remove: nothing
|
||||||
hosts: testhost
|
role_out: in role files
|
||||||
connection: local
|
play_out: in files
|
||||||
gather_facts: false
|
|
||||||
tasks:
|
|
||||||
- file: path={{playbook_dir}}/roles/showfile/files/testfile state=absent
|
|
||||||
- set_fact: role_out="in role tasks" play_out="in files" stage='remove 1'
|
|
||||||
|
|
||||||
- include: testplay.yml
|
- include: testplay.yml
|
||||||
|
vars:
|
||||||
- name: remove from role/tasks
|
remove: roles/showfile/files/testfile
|
||||||
hosts: testhost
|
role_out: in role
|
||||||
connection: local
|
play_out: in files
|
||||||
gather_facts: false
|
|
||||||
tasks:
|
|
||||||
- file: path={{playbook_dir}}/roles/showfile/tasks/testfile state=absent
|
|
||||||
- set_fact: role_out="in files" play_out="in files" stage='remote 2'
|
|
||||||
|
|
||||||
- include: testplay.yml
|
- include: testplay.yml
|
||||||
|
vars:
|
||||||
- name: remove from role dir
|
remove: roles/showfile/testfile
|
||||||
hosts: testhost
|
role_out: in role tasks
|
||||||
connection: local
|
play_out: in files
|
||||||
gather_facts: false
|
|
||||||
tasks:
|
|
||||||
- file: path={{playbook_dir}}/roles/showfile/testfile state=absent
|
|
||||||
- set_fact: role_out="in files" play_out="in files" stage='remove 3'
|
|
||||||
|
|
||||||
- include: testplay.yml
|
- include: testplay.yml
|
||||||
|
vars:
|
||||||
- name: remove from play/files
|
remove: roles/showfile/tasks/testfile
|
||||||
hosts: testhost
|
role_out: in files
|
||||||
connection: local
|
play_out: in files
|
||||||
gather_facts: false
|
|
||||||
tasks:
|
|
||||||
- file: path={{playbook_dir}}/files/testfile state=absent
|
|
||||||
- set_fact: role_out="in local" play_out="in local" stage='remove 4'
|
|
||||||
|
|
||||||
- include: testplay.yml
|
- include: testplay.yml
|
||||||
|
vars:
|
||||||
|
remove: files/testfile
|
||||||
|
role_out: in local
|
||||||
|
play_out: in local
|
||||||
|
|
||||||
- name: cleanup
|
- name: cleanup
|
||||||
hosts: testhost
|
hosts: testhost
|
||||||
|
|
|
@ -2,13 +2,16 @@
|
||||||
hosts: testhost
|
hosts: testhost
|
||||||
connection: local
|
connection: local
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
|
pre_tasks:
|
||||||
|
- name: remove {{ remove }}
|
||||||
|
file: path={{ playbook_dir }}/{{ remove }} state=absent
|
||||||
roles:
|
roles:
|
||||||
- showfile
|
- showfile
|
||||||
tasks:
|
post_tasks:
|
||||||
- name: from play
|
- name: from play
|
||||||
set_fact: play_result="{{lookup('file', 'testfile')}}"
|
set_fact: play_result="{{lookup('file', 'testfile')}}"
|
||||||
|
|
||||||
- name: output output {{stage}}
|
- name: output stage {{ remove }} removed
|
||||||
debug: msg="play> {{play_out}}, role> {{role_out}}"
|
debug: msg="play> {{play_out}}, role> {{role_out}}"
|
||||||
|
|
||||||
- name: verify that result match expected
|
- name: verify that result match expected
|
||||||
|
|
Loading…
Reference in a new issue