I provide an ec2 instance with the number of volumes connected to it. Follow my book to do the same.
---
- hosts: localhost
connection: local
gather_facts: false
vars:
instance_type: 't2.micro'
region: 'my-region'
aws_zone: 'myzone'
security_group: my-sg
image: ami-sample
keypair: my-keypair
vpc_subnet_id: my-subnet
tasks:
- name: Launch instance
ec2:
image: "{{ image }}"
instance_type: "{{ instance_type }}"
keypair: "{{ keypair}}"
instance_tags: '{"Environment":"test","Name":"test-provisioning"}'
region: "{{region}}"
aws_zone: "{{ region }}{{ aws_zone }}"
group: "{{ security_group }}"
vpc_subnet_id: "{{vpc_subnet_id}}"
wait: true
volumes:
- device_name: "{{ item }}"
with_items:
- /dev/sdb
- /dev/sdc
volume_type: gp2
volume_size: 100
delete_on_termination: true
encrypted: true
register: ec2_info
But getting the following error
fatal: [localhost]: FAILED! => {"failed": true, "msg": "the" args "field has an invalid value, which appears to contain an undefined variable. Error:" item "- undefined
If I replace {{item}}with /dev/sdb, the instance will be launched with the specific volume. But I want to create more than one volume with the specified list of items - / dev / sdb, / dev / sdc, etc. Any possible way to achieve this?