I started using ansible a few years ago and still learning every days.
At this time I’m working with hostvars as directory. Each host vars has a folder dedicated to datas.
When I run a playbook for this host, the file without extension is parsed by ansible-playbook .
This cause some issue because files could be OS conf files or binary.
I would like to know how is it possible to exclude files without extension or place in a specfic path to be parsed by ansible.
I tried multiple syntax on both without success.
I’ve searched some examples and didn’t find something usefull.
Maybe anyone could tell me what’s wrong with this ignore_patterns=['data_folder']
Although I’ve never actually used the ignore_patterns or ignore_extensions configuration options, I will point out that their descriptions say
List of (extensions|patterns) to ignore when using a directory as an inventory source.
However, you aren’t using these directories as an inventory source. You’re using them as variable sources. So I wouldn’t expect those options to have any effect on files in ./host_vars or ./group_vars directories.
There should not be any OS configuration or binary files in your ./host_vars or ./group_vars directories. Such files should be in a ./files (or ./templates) subdirectory, probably inside a role.
I’d also recommend against having any files under ./host_vars or ./group_vars that don’t have an extension of either .yml or .yaml. We used to do that, but quickly gave up the practice upon discovering that ansible-lint ignored any ./host_vars or ./group_vars files that had no such extension. (I don’t know whether that’s still the case, and I have no interest in finding out the hard way now.)
I’m curious what problems you’ve been attempting to solve by placing non-vars files in either ./host_vars or ./group_vars. If you’d care to tell us more about that, I and others here would be happy to suggest some more canonical ways to achieve your goals.
Thanks @utoddl , you’re definitively right, I read too fast.
Those options were for inventory and not for variables.
I read your recommendations and I think we still have a lot to do to improve our way to work with ansible.
For the moment we’ll use the @vbotka proposal as a quick solution to achieve our goals.
I’ll need to rethink all our variable/inventory structure