ansible/ansible — pull request #9601 by cchurch (2014-11-24 03:01:51+00:00)
Title: Set delegate on connection plugin before calling connect()

The `host` argument currently passed to the connection plugin reflects the value of `ansible_ssh_host` or `delegate_to`, whereas inventory variables are looked up by hostname. Since `conn.delegate` is currently set after the `connect()` method is called on the plugin, it is not always possible to access host variables before connecting.

With this change, a connection plugin can use the following code to read host variables prior to making a connection:

def connect(self):
hostvars = self.runner.inventory.get_variables(self.delegate or self.host)
# do stuff with hostvars and connect
return self

I'm planning to use this approach to support additional host variables for authentication with a winrm connection, without having to handle these host variables as a special case within runner.