Connection plugin with user configuration coming from a variable

Hi All,

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?

Thanks,
Peter

[1] https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/connection/ssh.py

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.

myoption:
     description: ...
     vars:
          - name: myvariable

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?

Thanks,
Peter

[1] https://github.com/ansible/ansible/blob/devel/lib/ansible/playbook/play_context.py

[2] https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/action/set_fact.py

  1. szeptember 17., hétfő 21:41:48 UTC+2 időpontban Brian Coca a következőt írta:

I'm not sure if i'm understanding correctly, in any case, any plugin
can use the built in configuration, it does not only apply to shipped
Ansible plugins.
https://docs.ansible.com/ansible/devel/dev_guide/developing_plugins.html#plugin-configuration-documentation-standards

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.