ansible/ansible — pull request #1825 by jvantuyl (2013-01-04 03:39:39+00:00)
Title: Hostvars for connections

Same commits requested for [1814](https://github.com/ansible/ansible/pull/1814), just on a new branch (and slightly rebased). Original request text:

I'm currently struggling with a cloud provider that only offers randomly-generated root passwords on VM creation. This creates a bit of trouble in that I have to do some hackery to get the VMs to the point that I can SSH with a key-file. While I could run an individual run of ansible for each new host with the password on the commandline, this was less than optimal.

Since the inventory file seems to be the best place to put per-host values, I decided to put the passwords there. This also fits well into my plan to eventually write an inventory plugin which could fill these in trivially from the API.

To support this, I made the following changes:

Isolated the connection from the runner insofar as copying the variables off of the runner onto the connection. This prevented needed to mutate the runner each loop for different hostvars, which seemed bad.
Passed the inject dictionary down into connections. This was trivial because it's already available well before the connections are created. It also separated the general functionality of per-host config settings from the specific feature of adding support for SSH settings in the config file.
Actually use the inject dictionary for shadowing the execution-wide defaults for SSH username and password.
For the last change, I had to decide whether to have the inventory settings shadow the global settings or not. I chose to do so, though it's trivial to do it the other way around. If that's a sticking point (I'm agnostic, as I don't plan to use both together), please merge the first two commits (to minimize merging fun) and I'll rewrite the last one.

Thanks!