Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
In CentOS wget does not exist by default. And when it is not there,…
Browse files Browse the repository at this point in the history
… the or logic does not work as wanted. (#309)

Bugfix: module init-snippet-attach-ebs-volume

In CentOS `wget` does not exist by default. And when it is not there, the or logic does not work as wanted.
  • Loading branch information
Magicloud authored Mar 8, 2020
1 parent b4feb7f commit dad0d84
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 16 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,33 @@

### Examples

# v0.9.14

### Summary

New modules and function extendings.

### Modules

* dlm-lifecycle-policy: Merge dlm-lifecycle-iam-role.

* init-snippet-install-docker-yum: CentOS script to install docker/docker-compose.

* init-snippet-attach-ebs-volume: Working on CentOS now. Generates required device name now despite Linux differences.

* single-node-asg: Output the attached EBS Name tag for DLM to match.

* rds: RDS database.

* s3-remote-state: fix for #286.

* asg: add protect_from_scale_in and suspended_processes attrs.

### Examples

* No changes


# v0.9.13

### Summary
Expand Down
41 changes: 25 additions & 16 deletions modules/init-snippet-attach-ebs-volume/snippet.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,33 @@
${init_prefix}
export AWS_DEFAULT_REGION=${region}
VOLUME_ID=${volume_id}
INSTANCE_ID="$(wget -O- http://169.254.169.254/latest/meta-data/instance-id || curl http://169.254.169.254/latest/meta-data/instance-id)"
echo "${log_prefix} will attach $${VOLUME_ID} via the AWS API in ${region}"
while ! aws ec2 attach-volume \
if which wget; then
INSTANCE_ID="$(wget -O- http://169.254.169.254/latest/meta-data/instance-id)"
elif which curl; then
INSTANCE_ID="$(curl http://169.254.169.254/latest/meta-data/instance-id)"
fi

if [ "x$${INSTANCE_ID}" == "x" ]; then
echo 'OS not functioning'
else
echo "${log_prefix} will attach $${VOLUME_ID} via the AWS API in ${region}"
while ! aws ec2 attach-volume \
--volume-id "$${VOLUME_ID}" \
--instance-id "$${INSTANCE_ID}" \
--device '${device_path}'; do
echo "Attaching command failed to run. Retrying."
sleep '${wait_interval}'
done
echo "${log_prefix} $${VOLUME_ID} attached."

vol_id="$(echo "$${VOLUME_ID}" | tr -d '-')"
while [ ! -e /dev/disk/by-id/*-Amazon_Elastic_Block_Store_$${vol_id} ]; do
sleep '${wait_interval}'
done

dev_id="$(ls /dev/disk/by-id/*-Amazon_Elastic_Block_Store_$${vol_id} | head -1)"
dev_name="/dev/$(readlink "$${dev_id}" | tr / '\n' | tail -1)"
[ "$${dev_name}" == "${device_path}" ] || ln -s "$${dev_name}" "${device_path}"
echo "Attaching command failed to run. Retrying."
sleep '${wait_interval}'
done
echo "${log_prefix} $${VOLUME_ID} attached."

vol_id="$(echo "$${VOLUME_ID}" | tr -d '-')"
while [ ! -e /dev/disk/by-id/*-Amazon_Elastic_Block_Store_$${vol_id} ]; do
sleep '${wait_interval}'
done

dev_id="$(ls /dev/disk/by-id/*-Amazon_Elastic_Block_Store_$${vol_id} | head -1)"
dev_name="/dev/$(readlink "$${dev_id}" | tr / '\n' | tail -1)"
[ "$${dev_name}" == "${device_path}" ] || ln -s "$${dev_name}" "${device_path}"
fi

${init_suffix}

0 comments on commit dad0d84

Please sign in to comment.