Skip to content

Instantly share code, notes, and snippets.

@vietphan-billidentity
Forked from nitanka/create-ebs.yml
Created February 28, 2022 22:53
Show Gist options
  • Select an option

  • Save vietphan-billidentity/df2a22e783780bc58a722df4b7011340 to your computer and use it in GitHub Desktop.

Select an option

Save vietphan-billidentity/df2a22e783780bc58a722df4b7011340 to your computer and use it in GitHub Desktop.
Ansible: Adding EBS volume to an EC2 instance
---
- name: Creating a Volume
hosts: localhost
become: yes
tasks:
- name: Creating a Volume
ec2_vol:
aws_access_key: "{{ lookup('env', 'AWS_ACCESS_KEY_ID') }}"
aws_secret_key: "{{ lookup('env', 'AWS_SECRET_ACCESS_KEY') }}"
instance: '<instance-id>'
volume_size: <volume-size>
device_name: <device-name> #/dev/xvdf, /dev/xvdb
region: '<region-name>'
volume_type: <volume-type> #example gp2
register: ec2_vol
- name: Printing the volume information
debug: var=ec2_vol
- name: creating mount point (directory)
file:
state: directory
path: "< path >"
- name: formatting the volume
filesystem:
dev: "< MOUNT_VOLUME >"
fstype: "< VOLUME_FORMAT >" #ext4, ext3 etc
#the device mount depends on the system
- name: mounting the filesystem
mount:
name: "< path to mount point >"
src: "< MOUNT_VOLUME >"
fstype: "< VOLUME_FORMAT >" #ext4, ext3 etc
state: mounted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment