Skip to content
Fluffy Clouds and Lines

Adopting Persitent AWS EBS Volumes with Ansible

Ansible, Architecture, AWS1 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

The Code

1├── client-scripts
2│ ├── rdp-certificate.ini.tmpl
3│ └── request_rdp_cert.ps1
4├── demo_environment
5│ ├──
6│ ├──
7│ ├── terraform.tfstate
8│ ├── terraform.tfstate.backup
9│ ├──
10│ ├──
11│ └── windows_userdata.ps1


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!

© 2022 by Fluffy Clouds and Lines. All rights reserved.
Theme by LekoArts