Converts YAML into Bash Script
Usage: yaml2bash [-m] [-p <prefix>] [<filename>] [-v] [-h]
Options:
-m : handle as a file contains multiple documents
-p <prefix> : specify a prefix for variables, or "Y2B" by default
<filename> : specify a YAML file to parse, or it will wait for stdin
-v : show the current version and exit
-h : show this help message and exit
In a bash script;
#!/usr/bin/env bash
set -e
eval $(yaml2bash ./test/test.yaml)
# To refer an individual variable
echo $Y2B_hostname
y2b_value Y2B[hostname]
echo $Y2B_users_1_name
y2b_value Y2B[users][1][name]
# To traverse YAML structure
y2b_traverse Y2B
# To count chidren of an individual variable
y2b_count Y2B
y2b_count Y2B[users]
# To retrieve indexes of an array or keys of a mapping
y2b_keys Y2B
y2b_keys Y2B[users]
# In addition,
# To convert YAML into JSON
y2b_json Y2B
You can use Docker to execute yaml2bash as well.
$ docker run -i --rm ailispaw/yaml2bash < ./test/test.yaml
https://hub.docker.com/r/ailispaw/yaml2bash
- The converted variables work only with Bash version 4.
- It doesn't support YAML's Alias, Tag and Complex Mapping Key. (#1)
It's inspired by the following projects.
- https://github.com/clearlinux/micro-config-drive
- https://johnlane.ie/yay-use-yaml-in-bash-scripts.html
Copyright (c) 2017 A.I. <ailis@paw.zone>
Licensed under the GNU General Public License, version 2 (GPL-2.0)
http://opensource.org/licenses/GPL-2.0