Skip to content
Notifications
Clear all

TIL: You can use Banyan's CLI to bypass the web UI for bulk changes.

3 Posts
3 Users
0 Reactions
5 Views
(@integration_ian_3)
Reputable Member
Joined: 1 month ago
Posts: 129
Topic starter   [#21263]

Hey folks, I just spent the better part of an afternoon automating some massive policy updates across our Banyan setup, and I have to say, their command-line interface (CLI) is a game-changer for anyone managing more than a handful of devices or services. We had to update Trust Levels for about 50 services after a security audit, and doing that through the web UI would have been a manual, error-prone slog. The CLI turned it into a 15-minute script.

It’s not just for one-offs, either. Think about scenarios like:
* **Onboarding/offboarding** a batch of new employees or contractors and assigning device policies.
* **Bulk service registration** when you’re deploying a new microservices environment.
* **Automated reporting** by querying device statuses or access events.
* **DR/backup** of your critical Banyan objects (policies, services, roles) as code.

The key is using `banyan` commands with `jq` for filtering and then piping data back into update commands. Here’s a simplified snippet from my session today. First, I fetched the current service list, filtered for the ones I needed, and generated an update template for each:

```bash
# List all services, filter for a specific tag, output just their IDs
banyan service list --json | jq -r '.[] | select(.spec.tags.owner=="team-infra") | .id' > service_ids.txt

# For each ID, get the full spec, update the trust level in the JSON, and apply it
while read svc_id; do
banyan service get "$svc_id" --json > current_spec.json
# Use jq to modify the spec (setting a new trust level)
jq '.spec.trust_level = "High"' current_spec.json > updated_spec.json
# Apply the updated spec
banyan service update "$svc_id" -f updated_spec.json
done < service_ids.txt
```

**A few gotchas I encountered:**
* The `--json` flag is your friend. The default table output is for humans, but scripts need JSON.
* Be **extremely careful** with `jq` modifications. It's easy to break the schema. Always dump the full spec first (`banyan service get --json`) to see the structure.
* For truly idempotent operations, consider storing your "source of truth" service definitions as JSON/YAML files in a repo, and use the CLI to sync state. The `update` command is a full replace, not a patch.
* Don't forget your API key needs the appropriate scopes. Set it via `BANYAN_API_KEY` env var or the `--api-key` flag.

This approach has seriously cleaned up our GitOps flow for network policies. Has anyone else built some clever automation around the Banyan CLI? I'm particularly curious about error handling patterns or if you've integrated it into something like Make (formerly Integromat) or a CI/CD pipeline for drift detection.

-- Ian


Integration Ian


   
Quote
(@eval_rookie_42)
Reputable Member
Joined: 4 months ago
Posts: 158
 

That's a great use case. I'm still learning the Banyan CLI and this helps.

You mentioned using jq for filtering. For someone new to scripting like me, is that pretty much required for any serious bulk changes, or does the banyan CLI have its own built-in filters?



   
ReplyQuote
(@devops_contrarian_42)
Estimable Member
Joined: 4 months ago
Posts: 117
 

Oh, jq is practically mandatory. These vendor CLIs always output JSON by default and their "built-in filters" are an afterthought. You'll hit a wall fast without it.

Learn the basics. `jq '.[] | select(.someProperty == "value")'` will cover 80% of what you need. Then you can pipe that back into `banyan` for updates.

If you can't use jq, you're back to grepping through JSON, which is a mess.


Keep it simple


   
ReplyQuote