Skip to content

Commit

Permalink
Provide cloud-init status information
Browse files Browse the repository at this point in the history
  • Loading branch information
mika committed May 28, 2020
1 parent e1b97fc commit 105b2e3
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions quickconfig/003-cloud-init.sh
@@ -0,0 +1,34 @@
# cloud-init not installed/present
if ! [ -x $(which cloud-init) ] ; then
return 0
fi

# cloud-init service not running
if ! cloud-init status 2>/dev/null | grep -q 'status: running' ; then
return 0
fi

LINE+="print_line 'Cloud-init information:';"

if cloud-init query -l 2>/dev/null | grep -q userdata ; then
userdata=$(mktemp)
cloud-init query userdata > "${userdata}" 2>/dev/null

hostname=$(awk '/^hostname/ {print $2}' "${userdata}")
if [ -n "${hostname}" ] ; then
LINE+="print_line '-> Hostname: ${hostname}';"
unset hostname
fi

rm -f "${userdata}"
unset userdata
fi

instance_id=$(cloud-init query instance_id 2>/dev/null)
if [ -n "${instance_id}" ] ; then
LINE+="print_line '-> Instance ID: ${instance_id}';"
fi

LINE+='print_delim;'

display_entry() { return 0; }

0 comments on commit 105b2e3

Please sign in to comment.