Adopting Persitent AWS EBS Volumes with Ansible
— Ansible, Architecture, AWS — 1 min read
Lonely EBS Volumes
The world of cattle hearding in the cloud brings up new challenges. When running EC2 instances in a cattle like manner, it is highly likely that the need to retain data that is not in a database is required. Sometimes EFS will fit the need, sometimes an application will mandate block storage, not NFS.
This is where this solution comes to play. Using an Autoscaling Group (ASG) is the most likely way of managing a cattle-like instance on EC2. The persistent data will be stored on a seperate EBS volume that lives outside the lifecycle of the ASG.
This Ansible playbook performs a procedure which is documented commonly as an approach for dealing with this scenario. At a high level, from the context of an EC2 instance, the playbook;
- Identifies volumes to attach within the same AZ as the instance,
- Filters these volumes based on a matching role tag, and with a status of available,
- Attaches the volume,
- Identifies the nvme block device,
- Partitions, formats and mounts the disk
1├── client-scripts2│ ├── rdp-certificate.ini.tmpl3│ └── request_rdp_cert.ps14├── demo_environment5│ ├── main.tf6│ ├── provider.tf7│ ├── terraform.tfstate8│ ├── terraform.tfstate.backup9│ ├── userdata.sh10│ ├── variables.tf11│ └── windows_userdata.ps112└── README.md
There's not much else to say, invoke this ansible playbook as part of the userdata execution, to adopt your EBS volumes based on tags. Enjoy!