0

I get this:

[WARNING]:  * Failed to parse /ansible/inventory/path/thing.sh with script plugin: problem running
/ansible/inventory/path/thing.sh --list ([Errno 13] Permission denied:
'/ansible/inventory/path/thing.sh')
[WARNING]:  * Failed to parse /ansible/inventory/path/thing.sh with yaml plugin: We were unable to read
either as JSON nor YAML, these are the errors we got from each: JSON: Expecting value: line 1 column 1 (char 0)  Syntax Error
while loading YAML.   mapping values are not allowed in this context  The error appears to be in

That is nothing unexpected - /ansible/inventory/path is actually not an ansible inventory file. More clearly, it is used by the system, but only indirectly, the ansible configuration scan can not interpret it.

But that directory has a very good place there on other configuration reason.

I would politely ask ansible, to just ignore /ansible/inventory/path, despite that it is a subdirectory of the inventory.

What I would really like, if some .ansibleignore or similar thing would exist, where I can simply determinte the files which should be ignored by ansible inventory scan.

Does it exist?

peterh
  • 222
  • 1
  • 13

2 Answers2

1

After hunting a little in the ansible source code, I have found the "inventory_ignore_patterns". The setting with this name can actually ignore whole directories, or all files with a given extension, and so on.

Contrary its name, these are not patterns, but regular expressions with a full file name match.

They are matched against the induvidual files, while recursively walking the inventory tree.

This applies only if the inventory is specified as a directory.

For example, if your inventory looks like so:

- inv
  - host_vars
    - host1.yaml
    - host2.yaml
  - group_vars
    - group1.yaml
  - not_for_ansible <-- YOU WANT TO IGNORE THIS
    - data_file.yaml
    - really_annoying.conf
    - dangerous.json
  - datasets <-- YOU WANT TO IGNORE THIS
    - huge.yaml

Then put this in ansible.cfg:

inventory_ignore_patterns = ^not_for_ansible$, ^datasets$
peterh
  • 222
  • 1
  • 13
0

You could make an environment variable which loaded in all the files you (or exclude all the files you don't want ) and set this in your .bashrc file:

export ANSIBLE_INVENTORY=$(find ~/.ansible/inventory -type f \( -name "*.json" -o -name "*.yml" \) | tr '\n' ',')

Peter Turner
  • 1,482
  • 4
  • 18
  • 39