# Connection plugin with user configuration coming from a variable

**URL:** <https://forum.ansible.com/t/connection-plugin-with-user-configuration-coming-from-a-variable/28591>\
**Category:** Ansible Project\
**Created:** [September 17, 2018, 4:03pm UTC](https://forum.ansible.com/t/connection-plugin-with-user-configuration-coming-from-a-variable/28591 "2018-09-17T16:03:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Horvath](https://avatars.discourse-cdn.com/v4/letter/p/bb73d2/32.png) [@Peter\_Horvath](https://forum.ansible.com/u/Peter_Horvath)\
**Post date:** [September 17, 2018, 4:03pm UTC](https://forum.ansible.com/t/connection-plugin-with-user-configuration-coming-from-a-variable/28591/1 "2018-09-17T16:03:31Z")

</div>

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](https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/connection/ssh.py)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [September 17, 2018, 7:41pm UTC](https://forum.ansible.com/t/connection-plugin-with-user-configuration-coming-from-a-variable/28591/2 "2018-09-17T19:41:14Z")

</div>

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:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;description: ...  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: myvariable

---

<div class="post-metadata">

**Author:** ![Peter\_Horvath](https://avatars.discourse-cdn.com/v4/letter/p/bb73d2/32.png) [@Peter\_Horvath](https://forum.ansible.com/u/Peter_Horvath)\
**Post date:** [September 18, 2018, 8:25am UTC](https://forum.ansible.com/t/connection-plugin-with-user-configuration-coming-from-a-variable/28591/3 "2018-09-18T08:25:39Z")

</div>

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](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](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:

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [September 18, 2018, 1:43pm UTC](https://forum.ansible.com/t/connection-plugin-with-user-configuration-coming-from-a-variable/28591/4 "2018-09-18T13:43:06Z")

</div>

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](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.
