Better add_host support for provided cloud modules

I submitted a pull request several days ago to allow cloud modules to invoke add_host. I wanted to post the options that have been presented, to get some feedback.

I’ll start with the original idea…

Several months ago James Tanner had approached me about finding a way to allow the cloud modules invoke add_host to make it easier to perform that seemingly standard step when building a new cloud instance.

The initial idea was that a cloud module would return a data structure that contained a top level key of ‘add_host’ which would be a list of dictionaries to be used in creating the host. That would be the minimal requirements.

Adding to that, cloud modules could implement an attribute called ‘add_host’ that might have options like no/yes/list,of,groups in which no would disable the functionality, yes would enable based on the cloud modules default grouping or list,of,groups in which you could specify the list manually.

The newer idea, and the way we are likely to go…

Update ‘add_host’ to accept a new parameter called something like ‘result’, which would take a registered result from a cloud module, and add the newly created hosts to the in memory inventory.

I have a few things bouncing around in my head about the new idea.

  1. It requires no changes to the existing cloud modules
  2. I am not positive I like it accepting the full, registered result. In a way I more prefer it to just accept a list of dicts in which you could give it something like ec2.instances or rax.success
  3. There will likely need to be some logic to determine what the ‘name’ is, and what ‘ansible_ssh_host’ is set to. From the rax perspective I have a full grasp on that, but not really for ec2 or other modules.

Let me know your thoughts. Based on this discussion I’ll update my pull request accordingly.

Thanks!

Thanks Matt,

Yeah, we should have had that conversation here in a wider group so I could chime in. I think what I’d like to see is the add_host module take the following:

  • add_host: var=varname

And that can know to read the various return structures that are there.

I would not want the cloud modules to change signatures as that could cause problems, nor would I want the modules themselves to return something that would be auto-added, as that could be considered a security concern, as I like the explicitness of the call to add_host.

So, if we can make the add_host module know how to figure out the various cloud returns (and it would need to be all of them), that seems best.