Teleport: Support machine-readable output for `tsh ls`

Created on 3 May 2020  路  4Comments  路  Source: gravitational/teleport

Feature Request

The output of tsh ls is not easily readable by any kind of automated process at the moment.

It'd be great to add a flag to get JSON-formatted output from tsh ls that could be leveraged to make the output more usable by automated processes. The label output from nodes in particular is hard to process because it has variable length.

Motivation

A customer requested this and I thought it was a good idea.

Who's it for?

OSS User, Pro, Enterprise

c-sn feature-request good-starter-issue tsh

Most helpful comment

JSON with jq is a good generic solution.
Where possible, we can consider plaintext output too. For example tsh ls can output node names, one per line:

$ for node in $(tsh ls --output=text); do
  tsh ssh ${node} uptime
done

That way many use-cases don't need jq.

All 4 comments

+1 from another customer, to add JSON Output. They would then use an Ansible script to automate upgrading of specific nodes. e.g. Version=!4.2.9

I would propose tsh ls --output=json , this is a similar patten to AWS CLI. --query is another interesting implementation that we might want to consider for larger customers.

Also TIL https://jmespath.org/

I think JSON output is a great target in the short term as we've had a number of requests for that output format.

We have had one request for --query type usage that I know of, but I've always preferred sticking to the Unix Philosophy - "make each program do one thing well". jq's filtering is way better than anything we could build in tsh natively.

JSON with jq is a good generic solution.
Where possible, we can consider plaintext output too. For example tsh ls can output node names, one per line:

$ for node in $(tsh ls --output=text); do
  tsh ssh ${node} uptime
done

That way many use-cases don't need jq.

Was this page helpful?
0 / 5 - 0 ratings