I've put together a module, and would like to get some feedback on whether the idea is hated or usable - ie should I put it together as a pull request for the main development or not...
The idea is that sometimes you need to grab some data from a pool of data items - think of something like root passwords if you have a unique root password per machine policy, or software licenses, or ...
pooldata takes data in from json files. One parameter is the name of the file for this host/group/whatever (so you use a variable to make it appropriately unique). If that file exists then it is read and added to the current facts. If the file does not exist then a file from a pool directory is renamed into place and that file's contents returned.
Reactions?
[Database - why - I have a filesystem!]
Nigel.
Nigel,
pooldata takes data in from json files. One parameter is the name
of the file for this host/group/whatever (so you use a variable to
make it appropriately unique). If that file exists then it is read
and added to the current facts.
Sounds to me a bit like group_vars. What's the difference? Can you show
an example?
If the file does not exist then a
file from a pool directory is renamed into place and that file's
contents returned.
... as in returning defaults? If so, why would that file be renamed in
place. I dread the thought of having to enable that on some crazy
read-only file system...
-JP
Jan-Piet Mens wrote:
Nigel,
pooldata takes data in from json files. One parameter is the name
of the file for this host/group/whatever (so you use a variable to
make it appropriately unique). If that file exists then it is read
and added to the current facts.
Sounds to me a bit like group_vars. What's the difference? Can you show
an example?
in that case its not much different, but...
If the file does not exist then a
file from a pool directory is renamed into place and that file's
contents returned.
... as in returning defaults? If so, why would that file be renamed in
place. I dread the thought of having to enable that on some crazy
read-only file system...
OK, a fictional use case. Each node used within a service needs a service IP. You have a pool (directory) of service IPs, one per json file.
- name: Allocate a service IP
action:
pooldata
data_file=pools/service_ip/alloc/${ansible_fqdn}.json
pool_directory=pools/service_ip/pool
First time you use this with a machine it grabs a new service IP record, removing it from the pool. Subsequent times it reuses the same record it was given the first time round.
There are ways I could implement this without the rename (although would need permanent storage), but they are likely to involve more grovelling through the directory structure...
Nigel.
If you want to write a custom fact module or something or a custom
module that's totally fine and welcome, I think this is too
off-the-beaten-track for core.
Michael DeHaan wrote:
If you want to write a custom fact module or something or a custom
module that's totally fine and welcome, I think this is too
off-the-beaten-track for core.
Thats fine - I suspected it might suffer from a limited requirement.
I currently have some prototyping of what I described. I may in future look at using a database rather than a filesystem, but in any case I can easily run it locally without it needing to go into the mainline
Nigel.