# how to handle repeated module parameters?

**URL:** <https://forum.ansible.com/t/how-to-handle-repeated-module-parameters/16569>\
**Category:** Ansible Project\
**Created:** [October 21, 2014, 7:55am UTC](https://forum.ansible.com/t/how-to-handle-repeated-module-parameters/16569 "2014-10-21T07:55:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomas\_Karasek](https://avatars.discourse-cdn.com/v4/letter/t/f1d935/32.png) [@Tomas\_Karasek](https://forum.ansible.com/u/Tomas_Karasek)\
**Post date:** [October 21, 2014, 7:55am UTC](https://forum.ansible.com/t/how-to-handle-repeated-module-parameters/16569/1 "2014-10-21T07:55:23Z")

</div>

Hello,

I am testing OpenStack modules and I wonder if it’s possible to somehow “pre-define” a dictionary for a resource to avoid repeating parameter declarations. I have:

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [October 23, 2014, 4:56pm UTC](https://forum.ansible.com/t/how-to-handle-repeated-module-parameters/16569/2 "2014-10-23T16:56:13Z")

</div>

Hi Tomas,

Starting in 1.8 (the current devel branch) you should not need to specify these params if they are already environment variables - the module code should pick them up from the environment for you. There have been other recent improvements in the various OpenStack modules, so I would recommend checking out the development branch if you have not done so already.

Thanks!

---

<div class="post-metadata">

**Author:** ![Michael\_Hoglan](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@Michael\_Hoglan](https://forum.ansible.com/u/Michael_Hoglan)\
**Post date:** [October 24, 2014, 12:25am UTC](https://forum.ansible.com/t/how-to-handle-repeated-module-parameters/16569/3 "2014-10-24T00:25:55Z")

</div>

How about moving the common authentication values into their own key in the dictionary

- name: Test variable composition  
hosts: localhost  
gather\_facts: false  
vars:  
common:  
var1: var1  
shell: “{{ lookup(‘env’, ‘SHELL’) }}”  
test1:  
b: 2  
common: “{{ common }}”  
test2:  
b: 4  
common: “{{ common }}”  
tasks:
- debug: var=common
- debug: var=test1
- debug: var=test2

Output

(ansible)[ec2-user@ip-10-0-0-226 playbooks]$ ansible-playbook -i launched test\_output.yml

PLAY [Test variable composition] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK: [debug var=common] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“common”: {  
“shell”: “/bin/bash”,  
“var1”: “var1”  
}  
}

TASK: [debug var=test1] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“test1”: {  
“a”: 1,  
“b”: 2,  
“common”: {  
“shell”: “/bin/bash”,  
“var1”: “var1”  
}  
}  
}

TASK: [debug var=test2] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“test2”: {  
“a”: 3,  
“b”: 4,  
“common”: {  
“shell”: “/bin/bash”,  
“var1”: “var1”  
}  
}  
}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
localhost : ok=3 changed=0 unreachable=0 failed=0

Thanks!

Michael

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [October 24, 2014, 1:38pm UTC](https://forum.ansible.com/t/how-to-handle-repeated-module-parameters/16569/4 "2014-10-24T13:38:14Z")

</div>

Michael,

You can’t make up syntax and just have it automatically passed to the modules, the original poster is asking about passing parameters repeatedly to OpenStack.

Thomas,

To at least clean up your playbook, define a variable:

vars:  
auth\_url: “{{ lookup(‘env’, ‘OS\_AUTH\_URL’) }}”

Etc. Then you don’t need to repeat the unseemly lookup string each time.

–Michael
