Create-yml-from-bash-include
Jump to navigation
Jump to search
This is going to be VERY fragile, but does work for simple yaml. Overall it is last resort, but can get you out of a jam.
{
printf 'host_entries:\n'
while read -r -a line; do
[[ ${line[0]} ]] || continue # skip blank lines
[[ ${line[0]} = "#"* ]] && continue # skip comments
[[ ${line[0]} = 127.0.0.1 ]] && continue # skip localhost
set -- "${line[@]}" # assign words read from line to current argument list
ip=$1; shift # assign first word from line to ip
for name; do # iterate over other words, treating them as names
printf " %s:\n ip: '%s'\n" "$name" "$ip"
done
done
} </etc/hosts >yourfile.yaml
This is WRONG but works for this simple case. Creating a YML file from a vars file should be less problematic however since it is key=value
This will allow creating a YML file with bash substitutions.
example is for bosh!!
https://www.starkandwayne.com/blog/bashing-your-yaml/