Not an expert with Salt yet, but wow, saltstack is such a great tool! Like colored output? What about saving colors to your log files? Chrome extension inside (help needed!)
Hey, before we begin, I started playing around with colors in a terminal and tough it could be cool to have a chrome extension for this. Let’s create ANSI colors chrome extension together!
Alright let’s begin
Saltstack’s output has colors for the great good, green when result is pass, pink when it’s modified and red when it fails.
Easy to see when something goes wrong. Now when you start running commands on multiple servers, salt is very handy, but what if you’d like to share the output with a teammate? Go for it, copy paste, plain white/black text or take a screenshot of your terminal? Continue reading for a solution ;)
See Bash Prompt HOWTO: Colors for reference ;)
Here are some env variable colors
Colors and files
Now, depending on your shell, writing this to a shell with
> should keep these ANSI characters, so when you
cat the file again, you should see it with colors.
Read colored output from file
Depending on your shell environment,
less command may not need additional parameters, but if you try to pipe a colored file to
less and don’t get any colors, try with
Thanks to this answer on stackoverflow and its comments.
keep salt colored output
Haven’t talked much about salt in current post so lets begin. Writing salt output to a file doesn’t keep ANSI colors. Luckily for us, salt command has a
--force-color parameter added in salt issue #4121.
Solution to keep salt output looks like this:
Awesome, salt colors!
What about clear text (no color)?
I you want to remove colors from output, there are a few solutions available, here’s a question asking for a regex to remove ANSI Escape codes. My favorite answer is ansi-strip-cli npm module
No more colors :)
Otherwise, you can strip output with
perl -pe 's/\x1b\[[0-9;]*[mG]//g' which is perfect if you don’t want node.
So with salt, I managed to get both output using the following:
Prefer not to bloat your system with npm?
Now you can enjoy salt output in both ways :)
Thanks to tldr pages
Some random stuff because why not
Cool, you’ve reached this far, get lolcat for the lolz