Skip to content

Instantly share code, notes, and snippets.

@drscream
Last active August 29, 2015 14:19
Show Gist options
  • Save drscream/36936405865842397c8a to your computer and use it in GitHub Desktop.
Save drscream/36936405865842397c8a to your computer and use it in GitHub Desktop.
#!/bin/bash
# Thomas Merkel <[email protected]>
#
# use small bash script to update customer_metadata on all machines
# from global zone. Allow to run command after update. Example used
# for new munin node IPs.
key='munin_master_allow'
value='127.0.0.1 198.51.100.1 203.0.113.200'
cmd='bash /opt/core/var/mdata-setup/includes/50-munin-node.sh && svcadm restart munin-node'
vmadm list -o uuid -p | while read uuid; do
lines=$(vmadm get ${uuid} | json customer_metadata.${key} | wc -l | awk '{ print $1 }')
if [[ ${lines} -eq 0 ]]; then
echo "IGNORE: ${uuid}"
continue
fi
echo "UPDATE: ${uuid}"
echo '{ "set_customer_metadata": { "'${key}'": "'${value}'" } }' | vmadm update ${uuid}
zlogin ${uuid} "${cmd}" < /dev/null
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment