-
-
Save 40a/fb13c97ad5594671302a6c6abb1b2089 to your computer and use it in GitHub Desktop.
#salt #reclass parser - works as jq for yaml files, used to traverse all paths in #Salt reclass and find/grep tree paterns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# tl;dr | |
# yaml-grep; to extract partial branches based on the 'jq' regex pattern. | |
# install: | |
# wget https://gist.githubusercontent.com/epcim/f1c5b748fa7c942de50677aef04f29f8/raw/yg.sh -O yg; chmod +x yg | |
# usage: | |
# ./yg '.compute?.network' | |
# | |
# classes/system/nova/compute/cluster.yml | |
# {"engine":"neutron","host":"${_param:network_vip_address}","user":"neutron","password":"${_param:keystone_neutron_password}","port":9696,"tenant":"service" | |
PATTERN=$@ | |
PATTERN=${PATTERN:-.parameters} | |
export GOPATH=${GOPATH:-$HOME/go} | |
export PATH=$PATH:$GOPATH/bin | |
# with pure python yq (much slower) | |
# sudo pip install git+git://github.com/kyle-long/yq.git@master | |
# for i in $(find . -name "*.yml"); do echo $i; cat $i | yq -ec "..|${PATTERN}| select(.!=null)" || printf '\e[A\e[K'; done | |
# with go yaml2json | |
if [ command -v yaml2json &>/dev/null ]; then | |
if [ command -v go ]; then | |
go get github.com/bronze1man/yaml2json | |
pushd $GOPATH/src/github.com/bronze1man/yaml2json | |
go install | |
popd | |
else | |
echo "First install github.com/bronze1man/yaml2json" | |
fi | |
fi | |
for i in $(find . -name "*.yml"); do echo $i; cat $i | yaml2json | jq -e "..|${PATTERN}| select(.!=null)" || printf '\e[A\e[K'; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment