Config Files for Inventory Scripts

Howdy everyone,

I have a question around config files for inventory scripts.

So far there are several inventory scripts that also include config files which are individually contained.

I am currently working on adding a configuration file for rax.py and have chosen to just use ansible.cfg and the functionality provided in ansible.constants by importing it into my inventory script.

Is this an OK thing to do? Or would it be preferble to keep away from this?

In this case, I am using a config header of [rax].

I could easily still use get_config from ansible.cfg for config/env var/defaults and just specify another config file, but I don’t want to keep the config file next to the script, because this causes some issues when using an inventory dir with multiple files.

it seems looking for a config file in the os.path.basename of argv[0] for the inventory script is a reasonable approach.

I don’t think we should have inventory script settings in ansible.cfg because ansible.cfg contains a lot of examples about the core program, but inventory scripts are plugins, and don’t currently ship with ansible (though I think they should, in something like /usr/share at least)

Yeah, I am “against” looking for a config in os.path.basename because when you have an inventory directory, that has a script and a config in it, pointing ansible to that directory, will result in ansible trying to parse the config as an inventory file.

I’d like to have a set of places similar to ansible.cfg where the config file would go. It just seemed that instead of requiring yet another config file, since with pyrax you could potentially have, using ansible.cfg would/could be appropriate:

ansible.cfg
~/.rackspace_cloud_credentials
~/.pyrax.cfg

Adding another config file seems a terrible idea, and I’d like to keep the ansible stuff out of the pyrax config files since they aren’t really for pyrax.

If I don’t use ansible.cfg, I’ll likely have to revert to duplicating the code to find ansible.cfg, use os.path.basename on the found ansible.cfg, or requiring an ENV var to specify the location of the config file.

Ansible is set to ignore files ending in “.ini” in directories, so this may help with that specific problem.

You could also have something like RAX_INVENTORY_CFG to specify alternative paths.

What he said ↓ (default to INI in the same directory but have an
environment variable that can be used to specify an alternate path).