Skip to content

Commit

Permalink
feature: add support for symbolic links when passing "dir" (ansible#8…
Browse files Browse the repository at this point in the history
…0460)

* update the include_vars action plugin to always follow symbolic links when traversing directories
  • Loading branch information
kloud-byun authored Apr 14, 2023
1 parent bd6feeb commit 2e62724
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelogs/fragments/80460-add-symbolic-links-with-dir.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- include_vars - os.walk now follows symbolic links when traversing directories (https://github.com/ansible/ansible/pull/80460)
2 changes: 1 addition & 1 deletion lib/ansible/plugins/action/include_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def _traverse_dir_depth(self):
The default depth is unlimited.
"""
current_depth = 0
sorted_walk = list(walk(self.source_dir, onerror=self._log_walk))
sorted_walk = list(walk(self.source_dir, onerror=self._log_walk, followlinks=True))
sorted_walk.sort(key=lambda x: x[0])
for current_root, current_dir, current_files in sorted_walk:
current_depth += 1
Expand Down
25 changes: 25 additions & 0 deletions test/integration/targets/include_vars/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,28 @@
- assert:
that:
- baz.ansible_facts.foo|type_debug != "AnsibleUnsafeText"

- name: setup test following symlinks
delegate_to: localhost
block:
- name: create directory to test following symlinks
file:
path: "{{ role_path }}/test_symlink"
state: directory

- name: create symlink to the vars2 dir
file:
src: "{{ role_path }}/vars2"
dest: "{{ role_path }}/test_symlink/symlink"
state: link

- name: include vars by following the symlink
include_vars:
dir: "{{ role_path }}/test_symlink"
register: follow_sym

- assert:
that: follow_sym.ansible_included_var_files | sort == [hash1, hash2]
vars:
hash1: "{{ role_path }}/test_symlink/symlink/hashes/hash1.yml"
hash2: "{{ role_path }}/test_symlink/symlink/hashes/hash2.yml"

0 comments on commit 2e62724

Please sign in to comment.