Skip to content

Instantly share code, notes, and snippets.

@epcim epcim/
Last active Mar 29, 2019

What would you like to do?
#salt #reclass parser - works as jq for yaml files, used to traverse all paths in #Salt reclass and find/grep tree paterns
# tl;dr
# yaml-grep; to extract partial branches based on the 'jq' regex pattern.
# install:
# wget -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"
export GOPATH=${GOPATH:-$HOME/go}
export PATH=$PATH:$GOPATH/bin
# with pure python yq (much slower)
# sudo pip install git+git://
# 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
pushd $GOPATH/src/
go install
echo "First install"
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
You can’t perform that action at this time.