Showing posts with label Salt. Show all posts
Showing posts with label Salt. Show all posts
Friday, November 15, 2019
SaltStack
I had heard of Puppet. I had heard of Chef. And I knew Ansible quite well because someone I know looked at all three (Puppet, Chef and Ansible) and chose Ansible for our organization.
I had never heard of Salt.
Until now.
Mirantis uses Salt to manage OpenStack infrastructure.
So in having some familiarity with Ansible, it made sense to type into the search engine:
"ansible vs salt'.
Well, sure enough. Someone has done a comparison.
Ansible vs Salt
What I see a number of people doing with Salt, is running remote commands on nodes that they otherwise might not have access to. But - recently, I have started looking more into Salt and it appears to be architected quite similar to Ansible, and is also quite powerful.
One of the features I have recently played around with, is the ability to use "Salt Grains". You can get all kinds of "grains of information" from a host with Salt Grains. In my case, I am calling Salt and telling it to give me all of the grains for all of the hosts in JSON format - and then I parse the json and make a csv spreadsheet. Pretty cool.
There's a lot more. Like Salt States (equivalent to Ansible Modules I think?). There are Salt Pillars.
They use the "salt" theme pretty well in naming all of their extensions.
This link, is called Salt in Ten Minutes. Gives a pretty good overview.
Salt in Ten Minutes
This link, below, is quite handy in figuring out how to target your minions using regular expressions.
https://docs.saltstack.com/en/latest/topics/targeting/globbing.html#regular-expressions
Friday, November 8, 2019
Some handy sed commands for formatting a large concatenated json file
More on Salt later in a separate post, but I am using Salt to pull salt grains from a number of servers so that I can extrapolate out the gain items (in my case, serial number, operating system and so forth).
I ran into an issue where Salt concatenates the json file as a bunch of continguous blocks of json.
When you try to load this into a json parser, it fails.
So in researching how to split this file, I ran into one particularly clever person on the web who said, "don't SPLIT the file! just make it an array of json elements".
I wonder if this guy knew how much wisdom he expelled.
So - I needed some sed to "prepare" this file.
And here it is:
#!/bin/bash
# This script will take the huge json file from Salt and make it something we can parse by
# making each json block an array element.
# Step 1 - add commas between blocks
sed -i 's/^}/},/g' saltgraininfo.json
# Step 2 - remove that last comma out which I could not figure out how to do in Step 1 in same sed command.
sed -i '$s/,//g' saltgraininfo.json
# Step 3 - put a bracket in beginning of the file
sed -i '1s/^/[\n/' saltgraininfo.json
# Step 4 - put a bracket at the end of the file
sed -i '$s/}/}\n]/g' saltgraininfo.json
After I did this, I used Python and did a json.load on the file, and voila'! It loads!
On to the parsing now....
I ran into an issue where Salt concatenates the json file as a bunch of continguous blocks of json.
When you try to load this into a json parser, it fails.
So in researching how to split this file, I ran into one particularly clever person on the web who said, "don't SPLIT the file! just make it an array of json elements".
I wonder if this guy knew how much wisdom he expelled.
So - I needed some sed to "prepare" this file.
And here it is:
#!/bin/bash
# This script will take the huge json file from Salt and make it something we can parse by
# making each json block an array element.
# Step 1 - add commas between blocks
sed -i 's/^}/},/g' saltgraininfo.json
# Step 2 - remove that last comma out which I could not figure out how to do in Step 1 in same sed command.
sed -i '$s/,//g' saltgraininfo.json
# Step 3 - put a bracket in beginning of the file
sed -i '1s/^/[\n/' saltgraininfo.json
# Step 4 - put a bracket at the end of the file
sed -i '$s/}/}\n]/g' saltgraininfo.json
After I did this, I used Python and did a json.load on the file, and voila'! It loads!
On to the parsing now....
Subscribe to:
Posts (Atom)
SLAs using Zabbix in a VMware Environment
Zabbix 7 introduced some better support for SLAs. It also had better support for VMware. VMware, of course now owned by BroadSoft, has prio...

-
After finishing up my last project, I was asked to reverse engineer a bunch of work a departing developer had done on Kubernetes. Immediat...
-
Initially, I started to follow some instructions on installing Kubernetes that someone sent to me in an email. I had trouble with those, s...
-
I did some more work on Kubernetes. So the way Kubernetes was set up in here, was that SD-WAN traffic would be "routed" through...