NAME

Ansible::Util::Vars

VERSION

version 0.001

SYNOPSIS

$vars = Ansible::Util::Vars->new;

$href = $vars->getVar('foo');
$href = $vars->getVars(['foo', 'bar']);
$val  = $vars->getValue('foo');
 

DESCRIPTION

Read Ansible runtime vars into native Perl.

To indicate which vars to read, you use the variable dot notation similar to what is described in the Ansible documentation. Further information about the Perl implementation can be found in Hash::DotPath.

An optional cache layer is used to speed up multiple invocations.

ATTRIBUTES

vaultPasswordFiles

A list of vault-password-files to pass to the command line.

type: ArrayRef[Str]
required: no

cacheEnabled

Toggle to disable/enable caching.

type: Bool
required: no
default: 1

cacheExpireSecs

Controls how long to hold onto cached data.

type: Int
required: no
default: 10 min

hosts

Choose which managed nodes or groups you want to execute against. This format of this is exactly the same as defined in "Patterns: targeting hosts and groups" by the Ansible documentation.

type: Str
required: no
default: localhost

keepTempFiles

Keeps the generated tempfiles for debugging/troubleshooting. The tempfiles used are a playbook, template, and json output.

type: Bool
required: no
default: 0

keepTempFilesOnError

This is a toggle to keep the generated tempfiles when Ansible exits with an error.

type: Bool
required: no
default: 0

METHODS

All methods confess on error unless otherwise specified.

clearCache()

Clears any cached vars.

usage:

$vars->clearCache;

args:

none

disableCache()

Disables caching.

usage:

$vars->disableCache;

returns:

The previous value of the attribute 'cacheEnabled'.

args:

none

enableCache()

Enables caching.

usage:

$vars->enableCache;

returns:

The previous value of the attribute 'cacheEnabled'.

args:

none

getValue()

Fetches the value of the specified var.

usage:

$val = $vars->getValue($path);

returns:

The value found at the specified path.

args:

path

The path to the variable in dot notation. See Hash::DotPath for more info.

type: Str
required: yes

getVar($path)

Fetches the variable found at the specified path.

usage:

$href = $vars->getVar($path);

returns:

A hash reference containing the requested var. Note that this also includes each of the elements in the path. Examples:

$href = $vars->getVar('foo.bar');
Data::Printer::p($href);
\ {
  foo   {
      bar   "somevalue"
  }
}

$href = $vars->getVar('biz.0.baz');
Data::Printer::p($href);
\ {
  biz   [
      [0] {
          baz   "anothervalue"
      }
  ]
}
                      

args:

path

The path to the variable in dot notation. See Hash::DotPath for more info.

type: Str
required: yes

getVars([$paths])

Fetches the variables found at the specified path.

usage:

$href = $vars->getVars(['foo.0.bar', 'biz']);

returns:

A hash reference containing the requested vars. The characteristics are the same as described in "getVar" except that the vars are merged into a single hash ref.

args:

path

The path to the variable in dot notation. See Hash::DotPath for more info.

type: ArrayRef[Str]
required: yes