yioda / ansible-inventory-to-ssh-config

This is a python tool for updating ssh config from ansible inventory file.
MIT License
26 stars 6 forks source link

Support providing an ansible inventory directory instead of a single file #9

Open czocher opened 8 months ago

czocher commented 8 months ago

Thanks for your amazing work!

I'm thinking of adding a small change to the arguments - instead of a single inventory file some projects use a directory with multiple files per environment (dev, prod, test). It would be nice to be able to parse all the yml, yaml or toml files in that directory to create the ssh_config file.

What do you think about this idea?

This of course can be replaced with something like:

find $ANSIBLE_INVENTORIES_DIRECTORY -name "*.yaml" -exec aitsc {} \;

but having this built-in would probably be beneficial.

yioda commented 8 months ago

Hi @czocher , thanks for the suggestion!

If you mean that parsing all inventory file and then output to a single ssh_config file, I'm thinking about a problem that different environments' inventory files might have the same host name. For an example,

dev.yaml

[foo]
bar ansible_host=192.168.0.1

prod.yaml also has the same host name

[foo]
bar ansible_host=192.168.1.1

then the output bar host would be conflicted.

Another way is, parsing all inventory and then output to different ssh_config files according to the input file name. But this would need to specify several output file name which doesn't seem very convenient for this tool.

Anyway, I'm still thinking how to implement it, and any suggestions are very welcome!

czocher commented 8 months ago

That's true, we have a couple of options for this problem:

  1. Output multiple files
  2. Output one file but print a warning on name conflicts, let's assume we will either use the first one or the last one with a given name
  3. Output one file but print an error on name conflicts