OpenStackMetaDataJsonToShell

23rd June 2017 at 1:50pm
Bash cloud-config jq OpenStack

Convert OpenStack metadata in to shell variables:

$ curl -ksSL http://169.254.169.254/openstack/latest/meta_data.json | jq .meta
{
  "carp": "fish",
  "meat": "yummy",
  "cat": "mammal"
}
$ curl -ksSL http://169.254.169.254/openstack/latest/meta_data.json | jq -r ".meta|to_entries|map(\"\(.key)=\(.value|tostring|@sh)\")|.[]"
carp='fish'
meat='yummy'
cat='mammal'