From dad0d840b0eaabef420936fdd1c2e7889e5a96e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=BE=BE?= <1886157+Magicloud@users.noreply.github.com> Date: Sun, 8 Mar 2020 14:47:36 +0800 Subject: [PATCH] In CentOS `wget` does not exist by default. And when it is not there, 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. --- CHANGELOG.md | 27 ++++++++++++ .../snippet.tpl | 41 +++++++++++-------- 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf04424a..7f800b60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/modules/init-snippet-attach-ebs-volume/snippet.tpl b/modules/init-snippet-attach-ebs-volume/snippet.tpl index 6105b6f7..0bf91f1f 100644 --- a/modules/init-snippet-attach-ebs-volume/snippet.tpl +++ b/modules/init-snippet-attach-ebs-volume/snippet.tpl @@ -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}