gcloud dns managed-zones list along with record-sets count format - format

In the output of gcloud dns managed-zones list ,I want to show the name of dnsName, creationTime, name, networkName, visibility and the count of recrod-sets in each hosted-zone.
I used below command to get two output in two commands
#get hosted-zone and other values
gcloud dns managed-zones list --format='table(dnsName, creationTime:sort=1, name, privateVisibilityConfig.networks.networkUrl.basename(), visibility)'
#get record-sets for a hostedzone
gcloud dns record-sets list --zone=$zoneName |awk 'NR>1{print}'|wc -l
I think I can get this in a shell script by getting a list of hosted zone and then printing two output together.
But is there a better way to do in a single gcloud command ?

IIRC (!?), you'll need to issue both gcloud commands as each provides distinct data.
To your point, you should be able to easily combine the combine the commands using a shell script and iterating over each zone from managed-zones list, to issue record-sets list --zone=${i}.
If you'd like help, please include dummy data from the 2 commands and I'll draft something for you.

Related

Bash - access oc node properties

The problem is pretty simple, but I am struggling to understand where to even look for a solution. I want to iterate over a list of pods I retrieve from openshift and then output some of its properties.
In other words, what I want to do is this:
for node in $(oc get nodes);
do
echo ${node.name}
echo ${node.role}
done
Unfortunately that leads to the error "line 67: ${node.name}: bad substitution".
Just iterating over the nodes with echo node works fine, but it just lists all the properties with one line per property value.
the output of just oc get nodes is:
NAME STATUS ROLES AGE VERSION
avaloq-abcde-master-0-xyz Ready master 38d v1.xx
avaloq-abcde-master-1-dfs Ready master 38d v1.xx
avaloq-abcde-master-2-gsd Ready master 38d v1.xx
the output of
for node in $(oc get nodes -o name);
do
echo ${node}
done
is
node/avaloq-abcde-master-0-xyz
node/avaloq-abcde-master-1-dfs
node/avaloq-abcde-master-2-gsd
If I try to add another property via -o (the output format?), it throws the following error:
error: unable to match a printer suitable for the output format "roles", allowed formats are: custom-columns,custom-columns-file,go-template,go-template-file,json,jsonpath,jsonpath-as-json,jsonpath-file,name,template,templatefile,wide,yaml
What I expect is the following output
node/avaloq-abcde-master-0-xyz
master
node/avaloq-abcde-master-1-dfs
master
node/avaloq-abcde-master-2-gsd
master
I assume that is where my understanding is lacking. Is the "array of objects/ table" returned via "oc get nodes" not an array of objects but rather just a text list separated by tabs and return characters?
You can use something like this if you only need specific columns from oc get node command
oc get nodes | awk '{print $1, $3}'
which will print output like
avaloq-abcde-master-0-xyz master
avaloq-abcde-master-1-dfs master
avaloq-abcde-master-2-gsd master

Check if gcloud SQL instance exists

I have to delete a SQL instance if it exists. Else skip it.
I tried gcloud sql instances list --filter name=dev-foo
This returns
NAME DATABASE_VERSION LOCATION TIER PRIMARY_ADDRESS PRIVATE_ADDRESS STATUS
dev-foo POSTGRES_14 us-central1-a db-custom-1-1234 1.2.3.4 - RUNNABLE
Adding linux commands here
gcloud sql instances list --filter name=dev-kansal3-811a8004 | wc -l | xargs
wc -l has leading whitespace and returns 2 as output, xargs is used to remove whitespace. I need 1 as output not 2. Can someone help here?
Also, when SQL instance dev-foo doesn't exist. This command outputs
Listed 0 items.
0
Is there a way to avoid getting Listed 0 items.?
You can use --no-user-output-enabled flag with gcloud command to skip Listed 0 items
For Example:
gcloud sql instances list --no-user-output-enabled
Or you can use with
gcloud sql instances list --uri --no-user-output-enabled
As suggested by #intotecho

Extract the lines using sed or awk and save them in file

Dear Stackoverflow Community,
I am trying to grab the value or the part of the string or lines.
The Kubernetes init gives 2 kubeadm join commands.
I want to extract the first one and save it in a file and similarly extract the 2nd one and save it in a file.
Below is the text that I am trying to extract from the file:
You can now join any number of the control-plane node running the following command on each as root:
kubeadm join 10.0.0.0:6443 --token jh88qi.uch1l58ri160bve1 \
--discovery-token-ca-cert-hash sha256:f9c9ab441d913fec7d157c20f1c5e93c496123456ac4ec14ca8e02ab7f916d7fb \
--control-plane --certificate-key 179e288571e33d3d68f5691b6d8e7cefa4657550fc0886856a52e2431hjkl7155
Please note that the certificate-key gives access to cluster sensitive data, keep it secret!
As a safeguard, uploaded-certs will be deleted in two hours; If necessary, you can use
"kubeadm init phase upload-certs --upload-certs" to reload certs afterward.
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 10.0.0.0:6443 --token jh88qi.uch1l58ri160bve1 \
--discovery-token-ca-cert-hash sha256:f9c9ab441d913fec7d157c20f1c5e93c496123456ac4ec14ca8e02ab7f916d7fb
Goal -
Extract both kubeadm join commands and save them in different files for automation.
Commands Used till now -
sed -ne '/--control-plane --certificate-key/p' token
With the above command, I want to extract value if I can and save it in a file.
The other command -
awk '/kubeadm join/{x=NR+2}(NR<=x){print}' token
token is the filename
You didn't show the expected output so it's a bit of a guess but this:
awk -v RS= '/^ *kubeadm join/{print > ("out"NR); close("out"NR)}' file
should do what I think you want given the input you provided.

gcloud cli failing to add record when contents start with dash

I'm working with the LetsEncrypt dns-01 challenge system which entails dynamically creating a TXT record in Google Cloud DNS with specific content, so LE can assert proof of ownership for generating a wildcard certificate (so I can't use http-01). The problem is sometimes LE tells me to create a TXT record that starts with a "-", for example -E_DFDFHJKF1783FSHDJ. I cannot get the gcloud cli to properly accept this data no matter what I do.
Example:
gcloud dns record-sets transaction start --zone=myzone
gcloud dns record-sets transaction add "-E_ASDFSDF" --ttl=30 --zone=myzone --name=test --type=TXT
gcloud dns record-sets transaction remove "-A_DSFKHSDF" --ttl=30 --zone=myzone --name=test2 --type=TXT
If you run those commands and inspect the resulting transaction.yaml you can see whether it properly contains the right string. If it did it correct, you should see something like:
- kind: dns#resourceRecordSet
name: test.
rrdatas:
- '"ASDFASDF"'
ttl: 30
type: TXT
I am executing this via Node's child_process, but I have the issue even if I execute it directly from bash, so Node isn't really meaningful issue at the moment. I've tried echoing the value in. I've tried setting an environment variable and using that in the string.
No matter what I do I get an error like the following:
ERROR: (gcloud.dns.record-sets.transaction.add) unrecognized arguments: -E_ASDFSDF
It turns out some characters need to be escaped in the CLI. I can confirm that the following works:
gcloud dns --project=myprojectid record-sets transaction add "\-test123" --name=test.mydomain.com. --ttl=300 --type=TXT --zone=myzoneid

Get deployments counts on Ansible Tower

How to get deployment counts on Ansible Tower? Is there any way to get deployment counts using ansible tower REST API?
In respect of your question and comment
... or last jobs history list ...
you could use according the Ansible Tower REST API and Jobs - List jobs something like
curl --silent -u "${ACCOUNT}:${PASSWORD}" https://${TOWER_URL}/api/v2/jobs/ | jq .
which provides also a Sorting and Searching option, in example ?order_by=name.

Resources