# Complex set of default variables with custom plugin?

**URL:** <https://forum.ansible.com/t/complex-set-of-default-variables-with-custom-plugin/23301>\
**Category:** Ansible Project\
**Created:** [December 20, 2016, 9:51pm UTC](https://forum.ansible.com/t/complex-set-of-default-variables-with-custom-plugin/23301 "2016-12-20T21:51:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kamil\_Demecki](https://avatars.discourse-cdn.com/v4/letter/k/ba9def/32.png) [@Kamil\_Demecki](https://forum.ansible.com/u/Kamil_Demecki)\
**Post date:** [December 20, 2016, 9:51pm UTC](https://forum.ansible.com/t/complex-set-of-default-variables-with-custom-plugin/23301/1 "2016-12-20T21:51:44Z")

</div>

Hi,

I’m looking for a solution to limit size of required setup for set of environments.

Below it is small chunk of bigger setup where I’m defining variables having default values.

`

app\_datasources:

- Target: BackendDS  
Host: “{{ backed\_db.host }}”  
Port: “{{ backend\_db.port }}”  
Connection: “{{ backend\_ds\_connection }}”
- Target: WebDS  
Host: “{{ web\_db.host }}”  
Port: “{{ web\_db.port }}”  
Connection: “{{ web\_ds\_connection }}”

backend\_ds\_connection: “{{ default\_ds\_connection }}”

web\_ds\_connection: “{{ default\_ds\_connection }}”

default\_ds\_connection:

- { Name: TxQueryTimeout, Value: “true” }
- { Name: BlockingTimeout, Value: 30000 }  
`

I define variable backed\_db and web\_db variable for each inventory and I can re-define backend\_ds\_connection / web\_ds\_connection placeholders if I need`.`

Unfortunately this pattern doesn’t scale well. I need to create hundreds of “placeholders” where there is possibility to change that bit for environment.

I’m looking at vars\_plugins or action plugins to generate default values if they are not defined per hosts.

For example if host define variable backend\_ds.Connection.TxQueryTimeout = 100 then I would override what is defined with default\_ds\_connection, otherwise it would use default values.

`  
app\_datasources:

- “{{ backend\_ds }}”
- “{{ web\_ds }}”

backend\_ds:  
Target: BackendDS  
Host: “{{ backed\_db.host }}”  
Port: “{{ backend\_db.port }}”  
Connection: “{{ backend\_ds\_connection }}”

web\_ds:  
Target: WebDS  
Host: “{{ web\_db.host }}”  
Port: “{{ web\_db.port }}”  
Connection: “{{ default\_ds\_connection }}”

default\_ds\_connection:

- { Name: TxQueryTimeout, Value: “true” }
- { Name: BlockingTimeout, Value: 30000 }

`

What do you think is the best way to achieve that? Are vars\_plugins or action plugins right way to go?

Regards

Kamil Demecki  
``
