How to use morpheus tags key variable in an automation task script


I am very new to Automation Tasks and need some pointers. I would like to grab an Instances tag key and use that in a powershell script task in morpheus. I have already read through the documentation regarding script variables but I may have missed something. I do not see anything for an instances tag as a script variable.

Server abc123 has a tag that was assigned at provisioning of “Support Team: Admin group 1”.

I would like to do something like:

echo “<%=instance.tags%>”

With an expected output of:

Support Team: Admin group 1

Hey there!

So a bit confusing in this realm because of backwards compatibility. instance.tags is the Labels functionality in Morpheus. Long ago was called tags, prior to cloud tags really being a thing. That said, cloud tags are instance.metadata.

If you are doing a bash script to echo, assuming you have jq installed you can run this as context local (so runs on Morpheus) but against another server.

echo '<%=instance.metadata.encodeAsJson()%>' | jq .

as seen:

Then when you run that task against a server, you get:

1 Like

The encodeAsJson() isn’t always necissary, but the variable formatting is Groovy based and I wanted to ensure the data I got was JSON and not a list.

Also, note that the quoting around our variables isn’t actually required, but it inputs the variables as strings. So you need to be aware of what the Morpheus variable will output. Since JSON is double quotes " I wrapped the variable in single quotes to avoid any oddities when running my script.

1 Like

That was exactly what I was looking for. Thanks! :slight_smile: