PPA Tools PPA Tools: Dictionaries

Summary

This module contains actions used to process dictionaries.

Actions

ppa_tools.dictionaries.

create

Create a new dictionary using any number of keys & values.

Minimum Plugin Version: 3.4.0

Input

This action accepts any keys & values the new dictionary should contain.

Validation

Given this action accepts any inputs you supply, PPA cannot perform accurate validation in the Playbook editor.

Output

A dictionary containing the supplied keys & values.

Example

Creating a new dictionary called connection_info using both static values & variables:

1
2
3
4
5
6
7
8
- ppa_tools.dictionaries.create:
    port: 5986
    validate_cert: true
  load:
    address: secrets.ip_address
    username: secrets.username
    password: secrets.password
  save: connection_info

ppa_tools.dictionaries.

filter_from_list

Remove dictionaries from a list by testing the values of one or more keys.

A dictionary will be filtered if any of its keys match any filter.

Minimum Plugin Version: 3.1.0

Input
  • dictionaries: a list of dictionaries to filter

  • filters: a list of Filter dictionaries

Output

A list of dictionaries from dictionaries whose keys matched no filters.

Case Sensitivity

As of plugin version 5.1.0 all text filters will be case-insensitive.

Example
  • Getting all users from Active Directory & saving them as all_users

  • Filtering out users whose mail attribute is null or sAMAccountName contains admin

  • Saving the filtered users as filtered_users

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
- active_directory.users.get_all:
  load:
    domain_controller: domain_controller
  save: all_users

- ppa_tools.dictionaries.filter_from_list:
    filters:
      - key: mail
        type: is
        value: null
      - key: sAMAccountName
        type: contains
        value: admin
  save: filtered_users

ppa_tools.dictionaries.

get_key_values

Get the value of the supplied key from each supplied dictionary.

If the key is missing from any dictionaries its value will be null.

Minimum Plugin Version: 3.7.0

Input
  • dictionaries: a list of dictionaries to get the values from

  • key: the key to get from each dictionary

Output

A list of values retrieved from each dictionary using the supplied key.

Ordering

The order of the dictionaries is honoured when getting the values.

This means the first value in the outputted list will be from the first dictionary, etc.

Example

Extracting the sAMAccountName from each Active Directory user in a list:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
- active_directory.users.get_all:
  load:
    domain_controller: domain_controller
  save: all_users

- ppa_tools.dictionaries.get_key_values:
    key: sAMAccountName
  load:
    dictionaries: all_users
  save: all_samaccountnames

ppa_tools.dictionaries.

insert

Add a new key & value to a dictionary.

Minimum Plugin Version: 3.0.0

Input
  • name: the name of the new key

  • value: the value of the new key

  • dictionary: the dictionary to add the key to

Output

The original dictionary with the new key & value inserted.

Example

Adding a value supplied by the Task Operator to a secrets dictionary:

1
2
3
4
5
6
- ppa_tools.dictionaries.insert:
    name: ip_address
    value: "{{ ip_address }}"
  load:
    dictionary: vault_secrets
  save: vault_secrets

ppa_tools.dictionaries.

merge

Merge two dictionaries into a new dictionary.

Minimum Plugin Version: 3.0.0

Input
  • first: a dictionary to merge with second

  • second: a dictionary to merge with first

Output

A new dictionary containing the keys & values of from first & second.

Duplicate Keys

This action will fail if any keys appear in both first & second.

Example

Merging two dictionaries to create a single dictionary containing connection details:

1
2
3
4
5
6
7
8
- ppa_tools.dictionaries.merge:
    first:
      address: 192.168.45.123
      port: 22
    second:
      username: "{{ vault_secrets.username }}"
      password: "{{ vault_secrets.password }}"
  save: connection_details

The new connection_details variable will contain:

1
2
3
4
address: 192.168.45.123
port: 22
username: vault-username  # an example secret value
password: vault-password  # an example secret value