NAME

shell_var_reader - Read/run a shell script and return set variable in it.

SYNOPSIS

shell_var_reader -r <file> [-o <format>] [-p] [-s] [--tcmdb <dir>] [--cmdb_host <host>] [--host_vars <vars>] [--use_roles [01]] [-m <munger>] [-m <multi output base dir>]

FLAGS

-r <file>

The file to read/run.

-o <format>

The output format.

Default: json

Formats: json,yaml,toml,dumper(Data::Dumper),shell,multi

'multi' will write out JSON, YAML, TOML, to respectively named dirs. The -d can be used to specify the base dir, otherwise './' is used like below.

./json_confs
./shell_confs
./toml_confs
./yaml_confs

Multi also requires --cmdb_host to be defined or to be findable via --tcmdb.

-d <multi output base dir>

When using multi, this is the base directory used.

Default: .

-p

Pretty print. Not relevant to all outputs.

-s

Sort. Not relevant to all outputs.

-i <include>

Files to parse and include in the produced JSON, TOML, or YAML.

The included file may be either JSON, TOML, or YAML.

If a comma is included, everything before the comma is used as the key name to include the parsed data as. Otherwise it will me merged.

Include Examples...

Read in bar.json and include it as the variable foo.
-i foo,bar.json

Read in foo.toml and merge it with what it is being merged into taking presidence.
-i foo.toml

Read in a.json and merge it, then read in in b.json and merge it.
-i a.jsom -i b.toml

MUNGING FLAGS

-m <munger>

File containing code to use for munging data prior to output. The file will be read in and ran via eval.

The following are accessible and usable from with in it.

$found_Vars :: Hash reference containing the found variables with everything merged into it.
$format :: The output format to use.
$host_Vars :: The value of --host_vars .
@includes :: A array of containing the various values for -i .
$merger :: A Hash::Merge->new('RIGHT_PRECEDENT') object.
$munger_file :: The value of -m if specified.
$pretty :: If -p was specified or not.
$sort :: If -s was specified or not.
$tcmdb :: Path to the Rex TOML CMDB if specified.
$to_read :: The value of -r .
$use_roles :: The value of --use_rules .

To lets say you wanted to delete the variable 'foo', you could do it like below.

delete($found_vars->{foo});

Or if wanted to set .suricata.enable and a few others based on .SURICATA_INSTANCE_COUNT you could do it like below.

if ($found_vars->{SURICATA_INSTANCE_COUNT}) {
    $found_vars->{suricata}{enable}=1;
    $found_vars->{suricata_extract}{enable}=1;
    $found_vars->{snmpd}{extends}{suricata}{enable}=1;
    $found_vars->{snmpd}{extends}{suricata_extract}{enable}=1;
}

CMDB FLAGS

Includes data from a CMDB and merge it in. Will overwrite everything previous.

--tcmdb <dir>

Optionally include data from a Rex CMDB.

$tcmdb.'/.cmdb_type' contians the CMDB type to use. Lines matching /^#/ or /^[\ \t]$/ are ignored. The first line not matching those is used as the value to use for Rex CMDB.

If that file does not exist, TOML, is used. For more info see Rex::CMDB::TOML.

--cmdb_env <env>

Environment name to use with the CMDB.

Default :: undef

--env_var <vars>

If --cmdb_env is undef, check this comma seperated list JSON Paths in the currently found/included vars for the first possible hit.

Default :: SYSTEM_ENV

--cmdb_host <host>

Hostname to use when querying the CMDB.

Default :: undef

--host_vars <vars>

If --cmdb_host is undef, check this comma seperated list JSON Paths in the currently found/included vars for the first possible hit. For more info the path stuff, see JSON::Path.

Default :: HOSTNAME,REX_NAME,REX_HOSTNAME,ANSIBLE_HOSTNAME,ANSIBLE_NAME,NAME

--use_roles [01]

If roles should be used or not with the Rex TOML CMDB.

Default :: 1