how to handle repeated module parameters?

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:

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!

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

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