0

I have defined a variable in my defaults as a list:

aws-sec-group-name:
    - "es-external"
    - "elasticsearch-production"

I am trying to use the above variable in my task playbook as follows:

---
  - name: Create EC2 instances
    ec2:
      keyname: "{{ aws-key-name }}"
      #group: "{{ aws-sec-group-name }}"
      instance_type: "{{ aws-instance-type }}"
      image: "{{ aws-ami }}"
      wait: yes
      wait_timeout: 500
      count: 2
      instance_tags:
        Name: "{{ aws-tag-name }}"
      vpc_subnet_id: "{{ subnet-id }}"
      group: ["{{ aws-sec-group-name.[0] }}","{{ aws-sec-group-name.[1] }}"].

Which is not the right way.

Can someone tell me how to use list variable?

And also since the count is 2, I am also interested in knowing if i can add -1- and -2- in the Name tag?

1 Answer 1

2

Can someone tell me how to use list variable?

Here you are:

  1. Fix the name of the variable as they cannot contain dashes:

    aws_sec_group_name:
      - "es-external"
      - "elasticsearch-production"
    
  2. Use the variable:

    group: "{{ aws_sec_group_name }}"
    
Sign up to request clarification or add additional context in comments.

Comments

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.