Recursively iterate over directories and add all files as Pillar data.
Example configuration:
ext_pillar:
- file_tree:
root_dir: /path/to/root/directory
follow_dir_links: False
raw_data: False
The root_dir
parameter is required and points to the directory where files
for each host are stored. The follow_dir_links
parameter is optional
and defaults to False. If follow_dir_links
is set to True, file_tree will
follow symbolic links to other directories. Be careful when using
follow_dir_links
, the current implementation is dumb and will run into
infinite recursion if a recursive symlink chain exists in the root_dir!
If raw_data
is set to True, it will revert the behavior of the python
open() function, which adds a line break character at the end of the file,
in this case, the pillar data.
To fill pillar data for each host, file_tree recursively iterates over
root_dir
/hosts/id
(where id
is a minion ID), and constructs
the same directory tree with contents of all the files inside the pillar tree.
For example, the following root_dir
tree:
./hosts/
./hosts/test-host/
./hosts/test-host/files/
./hosts/test-host/files/testdir/
./hosts/test-host/files/testdir/file1.txt
./hosts/test-host/files/testdir/file2.txt
./hosts/test-host/files/another-testdir/
./hosts/test-host/files/another-testdir/symlink-to-file1.txt
will result in the following pillar tree for minion with ID "test-host":
test-host:
----------
files:
----------
another-testdir:
----------
symlink-to-file1.txt:
Contents of file #1.
testdir:
----------
file1.txt:
Contents of file #1.
file2.txt:
Contents of file #2.
To fill pillar data for minion in a node group, file_tree recursively
iterates over root_dir
/nodegroups/nodegroup
(where nodegroup
is a
minion node group), and constructs the same directory tree with contents of all
the files inside the pillar tree.
IMPORTANT: The host data take precedence over the node group data
For example, the following root_dir
tree:
./nodegroups/
./nodegroups/test-group/
./nodegroups/test-group/files/
./nodegroups/test-group/files/testdir/
./nodegroups/test-group/files/testdir/file1.txt
./nodegroups/test-group/files/testdir/file2.txt
./nodegroups/test-group/files/another-testdir/
./nodegroups/test-group/files/another-testdir/symlink-to-file1.txt
will result in the following pillar tree for minion in the node group "test-group":
test-host:
----------
files:
----------
another-testdir:
----------
symlink-to-file1.txt:
Contents of file #1.
testdir:
----------
file1.txt:
Contents of file #1.
file2.txt:
Contents of file #2.
salt.pillar.file_tree.
ext_pillar
(minion_id, pillar, root_dir=None, follow_dir_links=False, debug=False, raw_data=False)¶Find pillar data for specified ID.