I'm attempting to parse external IP addresses of GCP compute instances in an instance group, then separate them with commas, to inject into a configuration file for a software.
I've created a command that does this successfully on my Mac (10.14.6):
gcloud compute instances list --filter="name :(name-of-instance*)" \
--format="get(networkInterfaces[0].accessConfigs[0].natIP)" \
| tr '\n' ',' | sed s/.$//
which immediately outputs a list:
x.x.x.x,y.y.y.y,z.z.z.z
this command is then put into a bash script that will be running on a compute instance (running Ubuntu 1604LTS).
however, when I try on a test instance (Ubuntu 1604LTS), the previous command with the wildcard *
does not output anything.
I've tested this by removing the wildcard and specifying the full name of one of the instances, and it does output the external IP of that instance correctly:
gcloud compute instances list --filter="name :(name-of-instance-full)" \
--format="get(networkInterfaces[0].accessConfigs[0].natIP)" \
| tr '\n' ',' | sed s/.$//
I've tried with several Filter Expressions including name : (instanceName*)
, name ~ ^instanceName*
, name = instanceName*
(wildcards are not permitted for the =
expression so it fails everywhere).
I cannot tell if this is a bug in gcloud sdk or if I'm missing something about how filters work on GCP compute instances.
expected result on Ubuntu1604LTS when using wildcard:
x.x.x.x,y.y.y.y,z.z.z.z
(same as on Mac)
actual result when using wildcard: