官术网_书友最值得收藏!

How to do it...

To create an EBS volume, we can use an ec2_vol module. This will take the device name, the instance ID, the volume size, and the tag name as input parameters:

- name: Create EBS volume and attach to Instance
ec2_vol:
aws_access_key: "{{ access_key }}"
aws_secret_key: "{{ secret_key }}"
region: "{{ aws_region }}"
instance: "{{ item }}"
volume_size: 10
name: Public Instance 1
device_name: /dev/xvdf
with_items: "{{ ec2_public_instance.instance_ids }}"
register: ec2_vol

This task will create an EBS volume with the tag name as Public Instance 1 and size 10 GB. Once the EBS volume is ready, it will be attached to the EC2 instance we provided with the device name /dev/xvdf.

We should note here that in this task, name and device_name are two different parameters with their own significance. A name is used as a tag; whereas device_name is unique for a one-to-one mapping between an EC2 instance and EBS volume used by AWS EC2.

Also, we have used the same registered variable for the EC2 instance ID that we used in Elastic IPs. If the variable had details of more than one instance, then this task would have created the same number of volumes and would have mapped it one-to-one.

主站蜘蛛池模板: 黄龙县| 开平市| 虎林市| 牙克石市| 临清市| 栖霞市| 鄂托克前旗| 濮阳县| 西林县| 黄浦区| 镇雄县| 万年县| 游戏| 丹巴县| 隆林| 永安市| 靖远县| 江西省| 临夏市| 安义县| 岳阳市| 临城县| 黑河市| 炉霍县| 聂拉木县| 麦盖提县| 平舆县| 乐安县| 阜宁县| 荃湾区| 岑巩县| 岑巩县| 巴青县| 通河县| 泸州市| 阜南县| 久治县| 尉氏县| 安康市| 缙云县| 剑川县|