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:

---
   - quantum_network:
       auth_url: "{{ lookup('env', 'OS_AUTH_URL') }}"
       login_username: "{{ lookup('env', 'OS_USERNAME') }}"
       login_password: "{{ lookup('env', 'OS_PASSWORD') }}"
       login_tenant_name: "{{ lookup('env', 'OS_TENANT_ID') }}"

       name: "{{ network_name }}"

   - quantum_subnet:
       auth_url: "{{ lookup('env', 'OS_AUTH_URL') }}"
       login_username: "{{ lookup('env', 'OS_USERNAME') }}"
       login_password: "{{ lookup('env', 'OS_PASSWORD') }}"
       login_tenant_name: "{{ lookup('env', 'OS_TENANT_ID') }}"

       cidr: "{{ subnet_cidr }}"
       name: "{{ subnet_name }}"
[end of YAML]

All the OpenStack modules have the 4 authentication parameters, and I would
like to somehow remove the duplicity of declaring them every time again.

If it would be some OOP oriented programming language, I would create an
abstract class and inherit. If it would be python, I would create a base
dict and then copy it and extend it. I am not sure how to achieve this in
Ansible and YAML.

Is there a way to declare the auth values only one time?

Thanks.

Cheers,
Tomas

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/eae96cd0-a2f0-4b25-9a60-80ba113f7649%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • James Cammarata at Oct 23, 2014 at 4:56 pm
    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!
    On Tue, Oct 21, 2014 at 12:55 AM, Tomas Karasek wrote:

    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:

    ---
    - quantum_network:
    auth_url: "{{ lookup('env', 'OS_AUTH_URL') }}"
    login_username: "{{ lookup('env', 'OS_USERNAME') }}"
    login_password: "{{ lookup('env', 'OS_PASSWORD') }}"
    login_tenant_name: "{{ lookup('env', 'OS_TENANT_ID') }}"

    name: "{{ network_name }}"

    - quantum_subnet:
    auth_url: "{{ lookup('env', 'OS_AUTH_URL') }}"
    login_username: "{{ lookup('env', 'OS_USERNAME') }}"
    login_password: "{{ lookup('env', 'OS_PASSWORD') }}"
    login_tenant_name: "{{ lookup('env', 'OS_TENANT_ID') }}"

    cidr: "{{ subnet_cidr }}"
    name: "{{ subnet_name }}"
    [end of YAML]

    All the OpenStack modules have the 4 authentication parameters, and I
    would like to somehow remove the duplicity of declaring them every time
    again.

    If it would be some OOP oriented programming language, I would create an
    abstract class and inherit. If it would be python, I would create a base
    dict and then copy it and extend it. I am not sure how to achieve this in
    Ansible and YAML.

    Is there a way to declare the auth values only one time?

    Thanks.

    Cheers,
    Tomas

    --
    You received this message because you are subscribed to the Google Groups
    "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/ansible-project/eae96cd0-a2f0-4b25-9a60-80ba113f7649%40googlegroups.com
    <https://groups.google.com/d/msgid/ansible-project/eae96cd0-a2f0-4b25-9a60-80ba113f7649%40googlegroups.com?utm_medium=email&utm_source=footer>
    .
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAMFyvFjWjaGVYDDHiv%2BZ-Nu%3D58naDG0jpQRVEQkMu%3D1sP0NqNQ%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Michael Hoglan at Oct 24, 2014 at 12:25 am
    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:
           a: 1
           b: 2
           common: "{{ common }}"
         test2:
           a: 3
           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
    On Tuesday, October 21, 2014 2:55:23 AM UTC-5, Tomas Karasek wrote:

    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:

    ---
    - quantum_network:
    auth_url: "{{ lookup('env', 'OS_AUTH_URL') }}"
    login_username: "{{ lookup('env', 'OS_USERNAME') }}"
    login_password: "{{ lookup('env', 'OS_PASSWORD') }}"
    login_tenant_name: "{{ lookup('env', 'OS_TENANT_ID') }}"

    name: "{{ network_name }}"

    - quantum_subnet:
    auth_url: "{{ lookup('env', 'OS_AUTH_URL') }}"
    login_username: "{{ lookup('env', 'OS_USERNAME') }}"
    login_password: "{{ lookup('env', 'OS_PASSWORD') }}"
    login_tenant_name: "{{ lookup('env', 'OS_TENANT_ID') }}"

    cidr: "{{ subnet_cidr }}"
    name: "{{ subnet_name }}"
    [end of YAML]

    All the OpenStack modules have the 4 authentication parameters, and I
    would like to somehow remove the duplicity of declaring them every time
    again.

    If it would be some OOP oriented programming language, I would create an
    abstract class and inherit. If it would be python, I would create a base
    dict and then copy it and extend it. I am not sure how to achieve this in
    Ansible and YAML.

    Is there a way to declare the auth values only one time?

    Thanks.

    Cheers,
    Tomas
    --
    You received this message because you are subscribed to the Google Groups "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d6f2fc6a-1703-4a2e-a265-7a03a971ce94%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Michael DeHaan at Oct 24, 2014 at 1:38 pm
    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



    On Thu, Oct 23, 2014 at 8:25 PM, Michael Hoglan wrote:

    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:
    a: 1
    b: 2
    common: "{{ common }}"
    test2:
    a: 3
    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
    On Tuesday, October 21, 2014 2:55:23 AM UTC-5, Tomas Karasek wrote:

    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:

    ---
    - quantum_network:
    auth_url: "{{ lookup('env', 'OS_AUTH_URL') }}"
    login_username: "{{ lookup('env', 'OS_USERNAME') }}"
    login_password: "{{ lookup('env', 'OS_PASSWORD') }}"
    login_tenant_name: "{{ lookup('env', 'OS_TENANT_ID') }}"

    name: "{{ network_name }}"

    - quantum_subnet:
    auth_url: "{{ lookup('env', 'OS_AUTH_URL') }}"
    login_username: "{{ lookup('env', 'OS_USERNAME') }}"
    login_password: "{{ lookup('env', 'OS_PASSWORD') }}"
    login_tenant_name: "{{ lookup('env', 'OS_TENANT_ID') }}"

    cidr: "{{ subnet_cidr }}"
    name: "{{ subnet_name }}"
    [end of YAML]

    All the OpenStack modules have the 4 authentication parameters, and I
    would like to somehow remove the duplicity of declaring them every time
    again.

    If it would be some OOP oriented programming language, I would create an
    abstract class and inherit. If it would be python, I would create a base
    dict and then copy it and extend it. I am not sure how to achieve this in
    Ansible and YAML.

    Is there a way to declare the auth values only one time?

    Thanks.

    Cheers,
    Tomas
    --
    You received this message because you are subscribed to the Google Groups
    "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/ansible-project/d6f2fc6a-1703-4a2e-a265-7a03a971ce94%40googlegroups.com
    <https://groups.google.com/d/msgid/ansible-project/d6f2fc6a-1703-4a2e-a265-7a03a971ce94%40googlegroups.com?utm_medium=email&utm_source=footer>
    .

    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Ansible Project" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgxDF__7gK4w4JXwqmOCvxpBC6uyUnmGojEVdDHRh_%2BPXQ%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupansible-project @
postedOct 22, '14 at 7:44p
activeOct 24, '14 at 1:38p
posts4
users4

People

Translate

site design / logo © 2022 Grokbase