Often it’s desirable to source groups, host names, and variables from external systems – such as Cobbler, CMDB, LDAP, etc.
With commits just now, I’ve made this possible. It took about 30 lines of code and about 30 minutes to write, so not that bad. Ansible is proving extremely easy to hack on.
How does it work?
If the inventory file (default: /etc/ansible/hosts) is executable (chmod +x) by the user, it is treated as a script, and run.
When run with no arguments, it is expected to return a JSON data structure like this:
{
‘ungrouped’ : [ ‘host1’, ‘host2’ ],
‘webservers’ : [ ‘host3’, ‘host4’ ],
‘dbservers’ : [ 'host5, ‘host6’ ],
‘raleigh’ : [ ‘host1’, ‘host6’ ]
}
ETC.
When run with one argument … the name of the host from the previous result (i.e. host1), it returns the variables to be fed to that
host. This affects templating obviously, but these variables can be used inside arguments -a if you want, too.
{
‘key1’ : ‘value1’,
‘key2’ : ‘value2’,
}
ETC.
All of this is committed and available for testing now, but will work much better for everyone with a real example. My next step is to write a trivial cobbler inventory source that takes groups from --mgmt-classes and variables from --ks-meta.
Once done, this will be available in examples/ in the source tree, and I’ll add information about this feature to the API page.
–Michael