I am working on a custom connection plugin based on – (99% the same) – the built-in SSH connection type [1], which would need to take some configuration from playbook variables.
Unlike the standard SSH plugin, this would use custom playbook variable names, hence I cannot use the standard APIs to retrieve the values configured by the user.
Could someone please point me to the right direction and give me a sample on how to achieve this: reading a specific variable from the playbook within a connection plugin?
A variable is a variable, by the time the plugin gets it the origin is
not discernible. So using the current pulgin config system you just
need to either add an option that uses that variable as a config
source or if you are using it for an existing option, add it there.
Based on my understanding, options are done at the Ansible level, e.g. parameters for the default ssh transport are configured in the Playbook context [1], so I do not think I could just add further configuration options (say “foobar”) for my own transport, because apparently those things come from the Ansible runtime. That’s why I tried using a variable. If this is not correct, please explain in a bit more details how/where should I add the option registrations.
I am wondering if it would be possible to follow the same approach as used in set_fact [2] task (where variables should be usable in the expressions). Based on what I see, I believe I would need to get access to the “templar” used within my connection plugin: would that be possible somehow?
Currently, connection plugins are only given the data they require, so
unless you declare the variable via the configuration system, you
won't get the variable.