1

I got this ansible variable array, weblogic[1].name which will give me the name of the second array "manageServer1".

weblogic: [ { name: "adminServer" address: "1.1.1.1" port: 1701 ssl: 1702 }, { name: "manageServer1" address: "1.1.1.2" port: 1703 ssl: 1704 }, ]

How can I pass parameter x=1 on the array, this one won't work, weblogic[x].name or weblogic['x'].name?

I'm working on Ansible 2.6-2.7.

1 Answer 1

1

Commas are missing in the lists. See example below.

> cat test.yml
---
- hosts: localhost
  gather_facts: no
  vars:
    weblogic:
      - { name: "adminServer", address: "1.1.1.1", port: 1701, ssl: 1702 }
      - { name: "manageServer1", address: "1.1.1.2", port: 1703, ssl: 1704 }
  tasks:
    - debug: var=weblogic[item].name
      loop:
        - 0
        - 1


> ansible-playbook test.yml | grep weblogic
    "weblogic[item].name": "adminServer"
    "weblogic[item].name": "manageServer1"
Sign up to request clarification or add additional context in comments.

3 Comments

If I add x:1 on the vars:, it's fine. But as an extra-vars like -e x=1, it won't, ansible will throw "VARIABLE IS NOT DEFINED". I'm using ansible 2.7.1.
This one works! ansible-playbook -v -e '{"x": 1}' test.yml @Vladimir Botka --thanks a lot to shed some lights on this!
You're welcome. Read the doc. Simple quotes would be enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.