> For the complete documentation index, see [llms.txt](https://docs.keeper.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.keeper.io/keeperpam/secrets-manager/integrations/ansible/ansible-plugin.md). Agents can also search and read this documentation through its [MCP server](https://docs.keeper.io/~gitbook/mcp).

# Ansible Plugin

A collection of Ansible plugins that interact with your Keeper account and can be used in your automations.

![](https://762006384-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MJXOXEifAmpyvNVL1to%2F-MkdG-_u0H2AJBEVfeYf%2F-MkdG4aCrzLanoVIXeNo%2Fansible-plugin-header.jpg?alt=media\&token=70c9a583-5939-48cc-990b-65c60094663a)

## Features

* Retrieve secrets from the Keeper vault to use in Ansible Playbooks
* Update the value of secrets in the Keeper Vault from Ansible
* Create records from Ansible
* Remove records from the Keeper Vault
* Create, find, rename, and delete folders from Ansible
* Copy files from the Keeper Vault
* Preview changes with Ansible check mode

{% hint style="info" %}
For a complete list of Keeper Secrets Manager features see the [Overview](https://docs.keeper.io/keeperpam/secrets-manager/overview.md)
{% endhint %}

## Prerequisites

This page documents the Secrets Manager Ansible integration. In order to utilize this integration, you will need:

* Keeper Secrets Manager access (See the [Quick Start Guide](https://docs.keeper.io/keeperpam/secrets-manager/quick-start-guide.md) for more details)
  * Secrets Manager add-on enabled for your Keeper account
  * Membership in a Role with the Secrets Manager enforcement policy enabled
* A Keeper [Secrets Manager Application](https://docs.keeper.io/keeperpam/secrets-manager/about/terminology.md#application) with secrets shared to it
  * See the [Quick Start Guide](https://docs.keeper.io/keeperpam/secrets-manager/quick-start-guide.md) for instructions on creating an Application
* An initialized Keeper [Secrets Manager Configuration](https://docs.keeper.io/keeperpam/secrets-manager/about/secrets-manager-configuration.md)
  * The Ansible integration accepts both Base64 and JSON format configurations
* A supported Ansible engine: ansible-core 2.15.13 or later, but not the 2.17 series. Use a version that supports your Python version, and install it in the same Python environment as the Keeper Ansible module.
  * Since version 1.5.0, the Keeper package does not install, upgrade, or check Ansible. Install and manage ansible-core yourself.

## Installation

Due to the flexibility of Ansible, where you install the plugins depends on your Ansible installation and playbook locations.

### Install Keeper Ansible Module

#### Installation via Ansible Galaxy

The collection can be found on the [Ansible Galaxy website](https://galaxy.ansible.com/ui/repo/published/keepersecurity/keeper_secrets_manager/). You can install the collection with the follow command line.

```bash
$ ansible-galaxy collection install keepersecurity.keeper_secrets_manager
```

Ansible Galaxy collection uses long plugin names. The name is the collection name combined with the plugin name. For example, the `keeper_copy` plugin name when using Ansible Galaxy is `keepersecurity.keeper_secrets_manager.keeper_copy`. If you want to use the short plugin name, add `keepersecurity.keeper_secrets_manager` to the `collections` block of your playbook.

```yaml
- name: Keeper Copy
  hosts: my_hosts
  collections: 
    - keepersecurity.keeper_secrets_manager
  
  tasks:
    - name: Copy a password
      keeper_copy:
        uid: RECORD UID
        ...
```

{% hint style="info" %}
Installing via Ansible Galaxy assumes you already have Ansible installed. Ansible Galaxy cannot install dependencies. The following dependencies will need to be installed manually, via pip, into your the python library or virtualenv used by Ansible.

* keeper-secrets-manager-core>=17.3.0
* keeper-secrets-manager-helper>=1.1.2
* certifi>=2026.10.19

If you build an execution environment with `ansible-builder`, the `requirements.txt` in the collection installs these packages, so you do not need to install them by hand.
{% endhint %}

#### Installation via Pypi

Install the Ansible engine and the Keeper module in the same Python environment. If you use a virtual environment, activate it first. Make note of the location where the module is installed, as this will be needed in the Ansible playbook configuration.

```bash
$ python3 -m pip install -U 'ansible-core>=2.15.13,!=2.17.*'
$ python3 -m pip install -U keeper_secrets_manager_ansible
```

Then verify the engine:

```bash
$ python3 -m pip show ansible-core
$ python3 -c "import ansible, sys; print(sys.executable); print(ansible.__version__); print(ansible.__file__)"
```

The version must be 2.15.13 or later and not in the 2.17 series. The printed interpreter and Ansible location must belong to the environment that you use for the Keeper module. An Ansible installation in a different interpreter or virtual environment does not count.

Installing or upgrading only `keeper_secrets_manager_ansible` does not install, upgrade, or check Ansible. A passing `pip check` does not show that the engine is in the supported range.

{% hint style="info" %}
Requires Python 3.9.2 or later and ansible-core 2.15.13 or later, but not the 2.17 series. The Python package does not install or upgrade ansible-core, so install a supported version yourself. The Galaxy collection shows a warning with an unsupported ansible-core and still runs, unless `collections_on_ansible_version_mismatch = error` is set in your Ansible configuration. We test ansible-core 2.15.13 and the 2.16, 2.18, 2.19, 2.20, and 2.21 series. ansible-core versions before 2.15.13, and the 2.17 series, are not supported. For the releases that upstream maintains, see the [ansible-core support matrix](https://docs.ansible.com/projects/ansible/latest/reference_appendices/release_and_maintenance.html).
{% endhint %}

For more information see the [PyPi page](https://pypi.org/project/keeper-secrets-manager-ansible/).

Find the Keeper Secrets Manager Ansible Plugin source code in the [GitHub repository](https://github.com/Keeper-Security/secrets-manager/tree/master/integration/keeper_secrets_manager_ansible).

The Keeper ansible plugins are installed in the site-packages directory of your version of Python or your current virtual environment. After you verify the engine, find the plugin locations with the following command. Run it in the same environment. If the command directory is not on your **PATH**, run `python3 -m keeper_secrets_manager_ansible --config` instead. The command only shows paths. It does not create a configuration file or use a one-time token:

```bash
$ keeper_ansible --config

# Below are the directory paths to action and lookup plugins.
ANSIBLE_ACTION_PLUGINS=...site-packages/keeper_secrets_manager_ansible/plugins/action
ANSIBLE_LOOKUP_PLUGINS=...site-packages/keeper_secrets_manager_ansible/plugins/lookup
```

Those paths can be used in your *ansible.cfg.*

```ini
[defaults]
action_plugins = ...site-packages/keeper_secrets_manager_ansible/plugins/action
lookup_plugins = ...site-packages/keeper_secrets_manager_ansible/plugins/lookup
```

### Generate a Config File

Prior to proceeding with this guide, make sure you meet all the [prerequisites](#prerequisites) and have the following:

* KSM Application and it's [One-Time Access Token](https://docs.keeper.io/keeperpam/secrets-manager/quick-start-guide.md)
* [Keeper Ansible module](#install-keeper-ansible-module) installed
* A supported Ansible engine installed in the same Python environment as the Keeper Ansible module (see the [prerequisites](#prerequisites))

In order to use the Ansible plugin for Keeper Secrets Manager, a [Keeper config file](https://docs.keeper.io/keeperpam/secrets-manager/about/secrets-manager-configuration.md) is required. Once you have a config file, the configuration values can be placed into the [Ansible variable](#ansible-variables) files. These variable files can be encrypted with Ansible vault.

Both `keeper_ansible --token ...` and `python3 -m keeper_secrets_manager_ansible --token ...` need Ansible in the Python environment that runs the command. Install and verify the engine before you create the configuration. An Ansible installation in a different interpreter or virtual environment does not satisfy this.

Using the Keeper Ansible module and the generated One-Time Access Token, generate a Configuration file:

```bash
$ keeper_ansible --token XX:XXXXXX
Config file create at location client-config.json
```

This will generate the Keeper JSON configuration file in the current directory.

If you do not have your Python module bin path added your **PATH** environment variable, you can create a config with the following command.

```bash
$ python3 -m keeper_secrets_manager_ansible --token XX:XXXXXX
Config file create at location client-config.json
```

The default name for the JSON configuration file is client-config.json. The content of the file will look like the following:

```json
{
    "appKey" : "XXXXXXXX",
    "appOwnerPublicKey": "XXXXXXX",
    "clientId": "XXXXXXXX",
    "hostname": "XXXXX",
    "privateKey": "XXXXXXXX",
    "serverPublicKeyId": "XX"
}

```

This config file allows your Ansible playbook to authenticate and retrieve designated secrets from the vault.

### Ansible Variables

The Keeper Secrets Manager plugins can use multiple configuration methods. For example, the Base64 encode configuration can be used.

```yaml
---
keeper_config: U09NRVRFc2R ... GFzZGFzZGFzZHNhWFQK==
```

Ansible can use the client-config.json config file directly. It can be specified in the Ansible variables using the keeper\_config\_file variable key.

```yaml
---
keeper_config_file: /path/to/client-config.json
```

Another solution is to place the values in your client-config.json file into an Ansible variable file. For example, the values can be placed into the *group\_vars, host\_vars, or in the task files:*

```yaml
---
keeper_app_key: XXXXX
keeper_client_id: XXXXX
keeper_token: XXXXX
keeper_private_key: XXXXX
keeper_app_owner_public_key: XXXXX
keeper_server_public_key_id: XX
```

For security, the *group\_vars* or *host\_vars* files can be encrypted with ansible-vault.

A list of valid Ansible Variables for the Keeper plugin are below:

<table data-header-hidden><thead><tr><th width="277.3333333333333">Ansible Variable</th><th width="185">JSON Key</th><th>Description</th></tr></thead><tbody><tr><td>Ansible Variable</td><td>JSON Key</td><td>Description</td></tr><tr><td>keeper_config</td><td>--</td><td>A Base64 encoded configuration string.</td></tr><tr><td>keeper_config_file</td><td>--</td><td>An alternative path and name for the JSON configuration file, if not current directory or named differently than <em>client-config.json</em>.</td></tr><tr><td>keeper_token</td><td>clientKey</td><td>The one time access token, also known as the client key. Only used to initialize the configuration.</td></tr><tr><td>keeper_client_id</td><td>clientId</td><td>The client id provided from Secrets Manager after the one time access token is used. Required.</td></tr><tr><td>keeper_app_key</td><td>appKey</td><td>The app key provided from the secret management service after the one time access token is used. Required.</td></tr><tr><td>keeper_private_key</td><td>privateKey</td><td>The private key provided from the secret management service after the one time access token is used. Required.</td></tr><tr><td>keeper_app_owner_public_key</td><td>appOwnerPublicKey</td><td>The public key used for creating records. Required if using the <code>keeper_create</code> plugin.</td></tr><tr><td>keeper_server_public_key_id</td><td>serverPublicKeyId</td><td>Selects which public key to use when connecting to the server. If the server wants a different public key the SDK will handle switching. Not required, but will reduce number of web service calls.</td></tr><tr><td>keeper_hostname</td><td>hostname</td><td>The Secrets Manager backend hostname. Defaults to US. Supports "US", "EU", "AU", "GOV", "JP" and "CA" values, or a server domain name, depending on your Keeper data center location. Used only when the configuration comes from the <code>keeper_*</code> variables. A configuration file or <code>keeper_config</code> supplies its own hostname. The <code>KSM_HOSTNAME</code> environment variable overrides every source.</td></tr><tr><td>keeper_log_level</td><td>--</td><td>Set the log level of the SDK. Acceptable levels are DEBUG, INFO, WARNING, ERROR, and CRITICAL. Defaults to ERROR. The Ansible options <code>-v</code> and <code>-vvv</code> override this variable. See Logging.</td></tr><tr><td>keeper_record_cache_secret</td><td>--</td><td>Required for the <code>keeper_cache_records</code> action. Used to encrypt records in cache. The value of this variable can be created in the playbook. See action example.</td></tr><tr><td>keeper_use_cache</td><td>--</td><td>Use a cache of the vault. Defaults to False. Cache file are only used as backup for network problems.</td></tr><tr><td>keeper_cache_dir</td><td>--</td><td>The directory to write and read the cache file.</td></tr><tr><td>keeper_record_types</td><td>--</td><td>An list of Keeper Commander record type definitions.</td></tr><tr><td>keeper_verify_ssl_certs_skip</td><td>--</td><td>Set to <code>true</code> to turn off TLS certificate verification for the Keeper server. Defaults to <code>false</code>. Accepts only boolean values. Used only when the configuration comes from the <code>keeper_*</code> variables or <code>keeper_config</code>. With a configuration file, only the <code>KSM_SKIP_VERIFY</code> environment variable can turn verification off. The plugins show a warning when verification is off.</td></tr><tr><td>keeper_force_config_write</td><td>--</td><td>Set to <code>true</code> to write the <code>keeper_*</code> variables to the configuration file, with mode 0600, instead of keeping them in memory. Defaults to <code>false</code>. Accepts only boolean values. Check mode never writes the file.</td></tr></tbody></table>

The plugins also read these environment variables:

* `KSM_TOKEN` - A one-time access token. When the configuration comes from the `keeper_*` variables, it overrides `keeper_token`.
* `KSM_HOSTNAME` - The Keeper server. It overrides the hostname from every configuration source.
* `KSM_SKIP_VERIFY` - Set to `true` to turn off TLS certificate verification. It applies to every configuration source.
* `KSM_CACHE_DIR` - The directory of the DR cache file. A value that you set here takes precedence over `keeper_cache_dir`.

The plugins do not read `KSM_CONFIG` and `KSM_CONFIG_FILE`. Use `keeper_config` and `keeper_config_file` instead.

{% hint style="info" %}
There are two caching methods in the plugin. They are not the same.\
\
`keeper_record_cache_secret` is used to cache records for a playbook run. After the playbook run, the cache is removed. The cache is stored in memory encrypted. This cache can be used to reduce the number of API called to the Keeper Secret Manager service. Since this cache is stored in memory, the more records retrieved the more memory is used.\
\
`keeper_use_cache` and `keeper_cache_dir` are used for Disaster Recovery caching of the Keeper Vault. This cache is stored encrypted on disk. When a request to the Keeper Secret Manager service fails, `keeper_get`, `keeper_copy`, `keeper_get_record`, `keeper_cache_records`, and the `keeper` lookup use the cached response and show a warning. `keeper_set`, `keeper_remove`, `keeper_create`, and the folder plugins never use it, so they fail during an outage.
{% endhint %}

### **Command Line Variables**

As an optional method, values can be passed in through the `ansible-playbook` command. Example:

```bash
$ ansible-playbook my_playbook.yml \
    -e "keeper_app_key=XXXXX" \
    -e "keeper_client_id=XXXXX" \
    -e "keeper_token=XXXXX" \
    -e "keeper_private_key=XXXXX"
```

## Ansible Plugin Usage

There are fifteen Keeper action plugins, one lookup plugin, and one stdout callback plugin (`keeper_redact`).

For `keeper_get`, `keeper_copy`, `keeper_set`, `keeper_get_record`, and the `keeper` lookup, the following arguments are used. Set exactly one of `uid` or `title`. Setting both fails the task.

* `uid` - The Record UID of the desired record.
* `title` - The Record Title of the desired record.
* `field` - Retrieve the value with specified label from the record.
* `custom_field` - Retrieve the value with the specific custom field name.
* `file` - Retrieve the file with the specified name from the record.

Except in `keeper_get_record`, set exactly one of `field`, `custom_field`, `file`, or `notes`. In `keeper_get`, `keeper_copy`, and the lookup, you can set `notation` instead of `uid`, `title`, and these options.

{% hint style="info" %}
To find out what fields and custom fields are available for a specific vault secret, use the Keeper Secrets Manager CLI "`ksm secret get -u XXXX`" command. More info [here](https://docs.keeper.io/keeperpam/secrets-manager/secrets-manager-command-line-interface/secret-command.md#secret-command).
{% endhint %}

{% hint style="info" %}
The plugin example are shown with the short plugin names. If you installed the collection via Ansible Galaxy, you will need to use the longer plugin name or add the collection name to the list of collections used in your playbook.
{% endhint %}

Actions can either use [Keeper Notation](https://docs.keeper.io/keeperpam/secrets-manager/about/keeper-notation.md) or the record UID or Title, combined with the task attributes `array_index` and `value_key` to get a specific value.

For example, a complex value like Phone number is an array of objects.

```json
[
    {
        'number': '(555) 123-1234', 
        'type': 'Work', 
        'ext': '11'
    }, 
    {
        'region': 'AD', 
        'number': '111-2223333', 
        'ext': '5555', 
        'type': 'Mobile'
    }
]
```

The example below shows how to use **Keeper Notation** and `array_index` and `value_key` to get the same result.

```yaml
---
- name: Keeper Get
  hosts: my_hosts
  # Include line below if installed via ansible galaxy or use long plugin names.
  # collections: 
  #   - keepersecurity.keeper_secrets_manager
  
  tasks:
    - name: Get the second phone number using Keeper Notation
      keeper_get:
        notation: "RECORD UID/field/phone[1][number]"
      register: second_number_notation
      
    - name: Get the second phone number using array_index and value_key
      keeper_get:
        uid: "RECORD UID"
        field: phone
        array_index: 1
        value_key: "number"
      register: second_number_non_notation
```

### Plugin: keeper\_cache\_records

The plugin `keeper_cache_records` is used to retrieve a select amount of records to be stored in a cache. The cache can then be used by other actions. This is used to reduce the number of API calls by getting all required record up front.

```yaml
---
- name: Cache records
  hosts: my_hosts
  # Include line below if installed via ansible galaxy or use long plugin names.
  # collections: 
  #   - keepersecurity.keeper_secrets_manager
  
  tasks:
    - name: Generate a Keeper Record Cache secret
      keeper_password:
        length: 64
      register: generated_password
      no_log: True

    - name: Store the Keeper Record Cache secret into variables.
      set_fact:
        keeper_record_cache_secret: "{{ generated_password.password }}"
      no_log: True
      
    - name: Cache records. Will use keeper_record_cache_secret from above.
      keeper_cache_records:
        uids:
          - RECORD UID
          - RECORD UID
        titles:
          - My Record Title
          - My Record Title Too
      register: my_records
      no_log: True
        
    - name: Copy a file
      keeper_copy:
        cache: "{{ my_records.cache }}"
        uid: RECORD UID
        file: my_cert_file.crt
        dest: /etc/special.crt
        owner: root
        group: root
        mode: "0644"
        backup: yes
```

The records can be retrieved by the record UID or by the record title. The result of the action is an encrypted serialization of the records. The result should be stored in Ansible by using the register variable so it can be used by other actions. The encrypted serialization of the records can be quite long. For security and reducing log noise, it is recommended to set `no_log` to **True**.

`keeper_cache_records` caches records only. It does not cache attached files. If an action attempts to retrieve an attached file from a record that came from the cache, an API call will be made to download the file.

Use templating to set the attributes in other actions. For example `cache: "{{ my_records.cache }}"`

`keeper_cache_records` requires the `keeper_record_cache_secret` to be set. This can be done in the host, group, task variables, or generated in a task and then set as a fact (variable). In the example above, the `keeper_password` action is used to generate a password which is then stored as `keeper_record_cache_secret`. The `no_log` attribute is set to True to prevent the secret from being logged.

{% hint style="warning" %}
In AWX and AAP, never set `keeper_use_cache`, `keeper_record_cache_secret`, `keeper_config_file`, or `keeper_cache_dir` from a launch-time extra variable or a survey answer. Also do not let such a variable supply the value that a task passes to `cache`. Extra variables have the highest precedence. They override the value that the playbook, the inventory, or a credential sets, and a registered variable with the same name. Keep `no_log: true` on the tasks that make or use the cache.
{% endhint %}

The cache will not update. The cache will not contain records created or updated after it has been generated. To get new records or changes in the cache, `keeper_cache_records` will need to be called again.

Version 1.5.0 stores the cache as encrypted JSON. Versions 1.2.0 to 1.4.0 stored it with pickle. A cache that version 1.4.0 or earlier made cannot be used. Run `keeper_cache_records` again to build a new cache.

The encryption key comes from `keeper_record_cache_secret` and from the host name of the machine that runs the plugins. That machine is the Ansible controller or the AWX execution environment container. A cache works only on the machine that made it. Use a long, random value for `keeper_record_cache_secret`.

If a task cannot read the cache that it gets in `cache`, the task shows a warning and reads the records from the vault. Examples are a cache that version 1.4.0 or earlier made, a cache that another machine made, and a wrong `keeper_record_cache_secret`.

#### Required Attributes

* `uids` - A list of Keeper Vault record UID.
* `titles` - A list of titles of Keeper Vault records.

The attributes `uids` and `titles` can be used at the same time. At least one of them needs to be set.

### Plugin: `keeper_copy`

The plugin `keeper_copy` is an extension of the [built-in copy plugin](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/copy_module.html)*.* Example:

```yaml
---
- name: Keeper Copy
  hosts: my_hosts
  # Include line below if installed via ansible galaxy or use long plugin names.
  # collections: 
  #   - keepersecurity.keeper_secrets_manager
  
  tasks:
    - name: Copy a password.
      keeper_copy:
        uid: RECORD UID
        field: password
        dest: /tmp/my_password
        mode: "0600"

    - name: Copy a file
      keeper_copy:
        uid: RECORD UID
        file: my_cert_file.crt
        dest: /etc/special.crt
        owner: root
        group: root
        mode: "0644"
        backup: yes
        
    - name: Copy record notes to file
      keeper_copy:
        uid: RECORD UID
        notes: yes
        dest: /tmp/record_notes.txt
        mode: "0600"
```

In the examples, a password will be copied from the Keeper vault record and stored in the file `/tmp/my_password` on the remote system. It will use the Ansible built-in copy plugin's mode attributes to change the permissions of the file.

The last task example from above, the file "*my\_cert\_file.crt*" will be copied from the Keeper vault record and stored at the location "*/tmp/special.crt"*. Several of the built-in copy plugin functions will be applied to the file.

#### Required Attributes

* `uid` - A Keeper Vault record UID.
* `title` - Title of a Keeper Vault records.
* `notation` - Use Keeper Notation to get the field from a record.

Set exactly one of `uid` or `title`, or use `notation` alone. Setting both `uid` and `title` fails the task. Unless you use `notation`, also set exactly one of `field`, `custom_field`, `file`, or `notes`.

#### Optional Attributes

* `cache` - The record cache from the `keeper_cache_records` action.
* `field` - Get the content from the standard Keeper Vault record.
* `custom_field` - Get the content from the custom Keeper Vault record.
* `file` - Get the content from the files attach to the Keeper Vault record by file title.
* `notes` - Set to `yes` to copy the notes field from the record. The notes field contains text notes attached to the record. Notes is a singleton field (only one per record), so it uses a boolean flag instead of a field name. Added in v1.3.0.
* `array_index` - Defaults to 0. If the field value contains multiple values, this attribute will allow you to select which item to return. The first item will have the `array_index` of **0**, and the next will be **1**, etc.
* `value_key` - If the field value is a complex object, this will allow you to select the key of the key/value pair to return.

Additional optional attributes are the same as the [built-in copy plugin](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/copy_module.html) attributes. The attributes `src, remote_src`, and `content` are not allowed and will be ignored.

With `--diff`, `keeper_copy` shows a placeholder instead of the old and the new file content, so the secret does not reach the console or the task result.

The task result keeps only the change and error fields, `dest`, `path`, `src`, `mode`, `owner`, `group`, `uid`, `gid`, `state`, `backup_file`, `diff`, and `invocation`. It does not return `checksum`, `md5sum`, or `size`, because a short secret can be found from a hash of it, and `size` gives its length.

### Plugin: `keeper_get`

{% hint style="success" %}
**New in v1.3.0**: You can now retrieve record notes using the `notes` parameter.
{% endhint %}

The plugin `keeper_get` will retrieve a field or file from a Keeper vault record. Example:

```yaml
---
- name: Keeper Get
  hosts: my_hosts
  # Include line below if installed via ansible galaxy or use long plugin names.
  # collections: 
  #   - keepersecurity.keeper_secrets_manager
  
  tasks:
    - name: Get login name. Loading record from Keeper Vault.
      keeper_get:
        uid: RECORD UID
        field: login
      register: my_login
      
    - name: Print login name
      debug:
        var: my_login.value
        verbosity: 0
        
    - name: Make a sudoer
      copy:
        dest: "/etc/sudoers.d/{{ my_login.value }}"
        content: |
          # Auto added by Ansible
          {{ my_login.value }} ALL=(ALL:ALL) ALL
          
    - name: Get record notes
      keeper_get:
        uid: RECORD UID
        notes: yes
      register: my_notes

    - name: Display notes
      debug:
        var: my_notes.value

    - name: Write notes to file
      copy:
        content: "{{ my_notes.value }}"
        dest: /tmp/record_notes.txt
```

The `keeper_get` plugin returns a dictionary. The key "value" in the dictionary will contain the desired field or file content. This plugin is normally paired with the Ansible `register` instruction and the returned value is stored in memory so it can be accessed by other tasks.

In the example above, a record containing user's login name is retrieved. The login name is then stored under the name my\_login. The second task will print the login name to your console for debug purposes. The third task will add a sudoer file for the login name with ability to execute all applications.

#### Required Attributes

* `uid` - A Keeper Vault record UID.
* `title` - Title of a Keeper Vault records.
* `notation` - Use Keeper Notation to get the field from a record.

Set exactly one of `uid` or `title`, or use `notation` alone. Setting both `uid` and `title` fails the task. Unless you use `notation`, also set exactly one of `field`, `custom_field`, `file`, or `notes`.

#### Optional Attributes

* `cache` - The record cache from the `keeper_cache_records` action.
* `field` - Get the value from the standard Keeper Vault record.
* `custom_field` - Get the value from the custom Keeper Vault record.
* `file` - Get the value from the files attach to the Keeper Vault record by file title.
* `notes` - Set to `yes` to retrieve the notes field from the record. The notes field contains text notes attached to the record. Unlike other fields, notes is a singleton field (only one per record), so it uses a boolean flag instead of a field name. Added in v1.3.0.
* `allow_array` - By default is **False**. If set to **True**, an array of values will be returned. This is needed if the field contains multiple values such as Phone numbers. If **True**, `array_index` and `value_key` will be ignored.
* `array_index` - Defaults to 0. If the field value contains multiple values, this attribute will allow you to select which item to return. The first item will have the `array_index` of 0, and the next will be 1, etc.
* `value_key` - If the field value is a complex object, this will allow you to select the key of the key/value pair to return.

{% hint style="info" %}
To **update** record notes, use the [`keeper_set`](#plugin-keeper_set) plugin with `notes: yes` and `value:`.
{% endhint %}

### Plugin: `keeper_get_record`

The plugin `keeper_get_record` will retrieve all the fields in the record and return them in a dictionary. Example:

```yaml
---
- name: Keeper Get Record
  hosts: my_hosts
  # Include line below if installed via ansible galaxy or use long plugin names.
  # collections: 
  #   - keepersecurity.keeper_secrets_manager
  
  tasks:
    - name: Get a record from the vault.
      keeper_get_record:
        uid: RECORD UID
        allow:
          - login
          - password
      register: my_record
      
    - name: Print login name
      debug:
        var: my_record.record.login[0]
        verbosity: 0
```

The `keeper_get_record` plugin returns a dictionary. The keys of the dictionary are the normalized field labels, or types. The keys will be alphanumeric and the underscore characters. If there are duplicate key, a number will be appended to the end of the key.

In the example above, a record is retrieved using the UID. The fields will be stored in a dictionary, in memory, using the `register` instruction. Since the `allow` attribute is used, the dictionary will only contain **login** and **password** .The field values can be accessed using the normal the templating in Ansible. The values will be stored as arrays. This is due to some fields returning arrays of the values, such as `phone`.

#### Required Attributes

* `uid` - A Keeper Vault record UID.
* `title` - Title of a Keeper Vault records.

Set exactly one of `uid` or `title`. Setting both fails the task.

#### Optional Attributes

* `cache` - The record cache from the `keeper_cache_records` action.
* `allow` - A list of keys to allow. If set, if the key is not in the list, it will not be inclued in the dictionary.

### Plugin: `keeper_set`

The `keeper_set` plugin has the ability to write a value into an existing Keeper vault record.

{% hint style="success" %}
**New in v1.3.0**: You can now update record notes fields using `keeper_set` with `notes: yes` and `value:`.
{% endhint %}

{% hint style="info" %}
To **retrieve** record notes, use the [`keeper_get`](#plugin-keeper_get) plugin with `notes: yes`.
{% endhint %}

Example:

```yaml
---
- name: Keeper Set
  hosts: my_hosts
  # Include line below if installed via ansible galaxy or use long plugin names.
  # collections: 
  #   - keepersecurity.keeper_secrets_manager
  
  tasks:
    - name: Get login name of new user.
      keeper_get:
        uid: RECORD UID
        field: login
      register: my_login
      
    - name: Add new user of remote machine.
      user:
        name: "{{ my_login.value }}"
        comment: "User {{ my_login.value }}"
      register: new_user
        
    - name: Update record with user's home directory in the Keeper Vault
      keeper_set:
        uid: RECORD UID
        custom_field: my_home_directory
        value: "{{ new_user.home }}"
        
    - name: Update Record Notes
      keeper_set:
        uid: RECORD UID
        notes: yes
        value: "Updated by Ansible on {{ ansible_date_time.iso8601 }}"
```

In this example, a new user's login name is retreived. The new user is created on the remote system with the login name from the record. The home directory on the remote machine is then updated in the record.

The `keeper_set` action does not have the ability of set individual values of an array or complex values. It simplely replaces the existing value with a new value. For example, for a **Hostname and Port** field type there is no way to just update the port. The entire value including the **hostName** needs to be included in the object value.

`keeper_set` reads the record from the vault and then saves the new value. It never reads the record from the DR cache or from a registered cache, because an old copy can select a renamed record or hide a needed save. During a Keeper outage the task fails.

`keeper_set` updates exactly one record. A selection by `title` also fails when `keeper-secrets-manager-core` could not read some record or folder, because the title cannot be confirmed as unique. Use the `uid` of a readable record. A `uid` that matches more than one live record fails the task. A list with one item for `uid` or `title` counts as that item, and a list with two or more items fails the task.

The task reports `changed: true` and `updated: true` only when it saves a new value. If the record already has the value, the task saves nothing and reports `changed: false` and `updated: false`. In check mode, the task reports the predicted `changed` value and `updated: false`.

`keeper_set` does not update a registered cache. To get the new value in a cache, run the `keeper_cache_records` action again with the **UID** or **Title** of the record that was updated.

#### Required Attributes

* `uid` - A Keeper Vault record UID.
* `title` - Title of a Keeper Vault records.

Set exactly one of `uid` or `title`. Setting both fails the task. Also set exactly one of `field`, `custom_field`, or `notes`, and set `value`.

#### Optional Attributes

* `field` - Update the existing standard Keeper Vault record field.
* `custom_field` - Update the existing custom Keeper Vault record field.
* `notes` - Set to `yes` to update the notes field in the record. The notes field contains text notes attached to the record. Notes is a singleton field (only one per record), so it uses a boolean flag instead of a field name. Added in v1.3.0.
* `value` - The new value to write to the record field.
* `cache` - Accepted for compatibility and ignored, because the task always reads the record from the vault. A task that sets `cache` shows a warning. Remove the option.

### Plugin: `keeper_create`

The `keeper_create` plugin creates a record in the Keeper vault. See the [Field/Record Types ](https://docs.keeper.io/keeperpam/secrets-manager/about/field-record-types.md)document for available record types, and the field types used to build the records. The action plugin will return the `record_uid` upon successful creation. The task reports `changed: true`. In check mode, the task validates the record, the shared folder key, and the folder hierarchy, creates no record, and returns a null `record_uid`.

{% hint style="info" %}
The Ansible variable `keeper_app_owner_public_key` is required to create a record. In the client-config.json, the JSON key is `appOwnerPublicKey.` If your configuration does not contain this key, create a new One-Time Access Token and initialize it.
{% endhint %}

Example:

```yaml
---
- name: Keeper Create
  hosts: my_hosts
  
  tasks:
    - name: "Create A Record"
      keeper_create:
        shared_folder_uid: XXXXXX
        record_type: login
        generate_password: True
        password_complexity:
          length: 64
          allow_symbols: False
        title: "My New Record"
        notes: "Created by Ansible"
        version: v3
        fields:
          - type: login
            value: johndoe@localhost
          - type: url
            value: https://localhost
        custom_fields:
          - type: text
            label: "My Custom Label"
            value: "My custom value"
      register: my_new_record

    - name: "New Record UID"
      debug:
        msg: "New record uid is {{ my_new_record.record_uid }}"
```

The following fields are required.

* `shared_folder_uid` - The Shared Folder UID from the vault. The record will be created within this folder. This must be a shared folder UID, not a subfolder UID. To create the record in a subfolder, set `subfolder_uid`.
* `record_type` - The type of record. This will included all the default record types. If the `keeper_record_types` is set, those record types can be used.
* `title` - The title of record

The following fields are optional.

* `subfolder_uid` - The UID of an existing subfolder inside `shared_folder_uid`. The record is created in this subfolder. The subfolder must be shared to the KSM application and must be inside `shared_folder_uid`. Otherwise the task fails, also in check mode. If omitted, the record is created directly in the shared folder. An empty or null value means no subfolder. Added in v1.5.0.
* `version` - The record schema version to use. Defaults to `v3` (recommended). Accepts `v2` or `v3`. Available since v1.1.2.
* `generate_password` - If set to true, any password field where the password has not been set, will be populated with a random generated password.
* `password_complexity` - Sets the complexity of the password. All parameters of password\_complexity are optional.
  * `length` - Length of password. Defaults to **64**.
  * `allow_lowercase` - Defaults to **True**. If set to **False**, no lowercase letters will be used.
  * `allow_uppercase` - Defaults to **True**. If set to **False**, no uppercase letters will be used.
  * `allow_digits` - Defaults to **True**. If set to **False**, no digits will be used.
  * `allow_symbols` - Defaults to True. If set to **False**, no symbols will be used.
  * `filter_characters` - A list of characters to exclude from the password. This allows to remove characters a services will reject. For example, '%' in SQL. If not set, the password will not be filtered.
* `notes` - Attach a note to the record.

{% hint style="info" %}
Password generation will use the following symbols: "!@#$%()+;<>=?\[]{}^.,
{% endhint %}

Based on the Record Types, certain fields maybe required. Custom fields are optional. Both `fields` and `custom_fields` are an array of values.

* `fields/custom_fields`
  * `type` - Field type
  * `label` - Label to display with the value.
  * `value` - Field value. Can be a string or dictionary based on field type.

#### Creating Custom Record Types

To create a record with a particular Custom Record Type, first export the custom record types using Keeper Commander and the `record-type-info` command. KSM does not sync down the custom type definitions, so this must be added directly to the playbook as a variable.

Keeper Commander will output a JSON Array ("content"). Only the JSON object is required.

Example:

```
My Vault> record-type-info --format json -lr "My Custom"
[
  {
    "recordTypeId": 18,
    "content": "{\"$id\":\"My Custom\",\"categories\":[\"login\"],
      \"description\":\"SSH key template\",\"fields\":[
        {\"$ref\":\"login\"},
        {\"$ref\":\"keyPair\"},
        {\"$ref\":\"password\",\"label\":\"passphrase\"},
        {\"$ref\":\"host\"},
        {\"$ref\":\"fileRef\"}]}"
  }
]
```

In your Ansible YAML file, add the value of the "content" object to the variable key called `keeper_record_types`. The variable is an array, and the JSON is to be treated as a string value. The pipe, after the array item, will treat the following JSON as a string. The variable will accept multiple record types.

Example:

```yaml
- name: My Playbook
  collections:
   - keepersecurity.keeper_secrets_manager
  hosts: "my_hosts"
  vars:
    keeper_record_types:
      - |
        {
          "recordTypeId": 35,
          "content": "{\"$id\":\"My Custom\",\"fields\":[{\"$ref\":\"fileRef\",\"label\":\"File or Photo\"},{\"$ref\":\"login\",\"label\":\"Login\"},{\"$ref\":\"password\",\"label\":\"Password\",\"required\":true,\"enforceGeneration\":false,\"privacyScreen\":false,\"complexity\":{\"length\":8,\"caps\":0,\"lowercase\":0,\"digits\":0,\"special\":0}},{\"$ref\":\"text\",\"label\":\"System Login\",\"required\":true},{\"$ref\":\"secret\",\"label\":\"System Password / Pin Code\"},{\"$ref\":\"url\",\"label\":\"Keeper VPN Wiki\",\"required\":true},{\"$ref\":\"url\",\"label\":\"Password Best Practices FAQ's and Tips\",\"required\":true}]}"
        }
```

To check if this worked, the `keeper_info` plugin can be used to show which record types are available.

When creating a record of a particular custom type, the Ansible task will reference the record type name in the `record_type` parameter as seen below:

```yaml
- name: "Create A Custom Record"
      keeper_create:
        shared_folder_uid: XXXXXXXXXXXX
        record_type: "My Custom"
        title: "Example Custom Record"
        notes: "Created by Ansible"
        fields:
          - type: login
            label: Login
            value: johndoe@localhost
          - type: password
            label: Password
            value: "ABC123"
      register: my_new_record
```

### Plugin: `keeper_remove`

The `keeper_remove` plugin removes a record from the Keeper vault. Added in v1.2.1.

* If the record does not exist, or it is not shared to this KSM application, the task succeeds with `changed: false`.
* A title that matches more than one record fails the task and lists the matching UIDs. Nothing is deleted.
* A record that `keeper-secrets-manager-core` cannot read fails the task and nothing is deleted. A removal by title also fails when the SDK could not read some record or folder, because the title cannot be confirmed as unique. Use the UID of a readable record.
* A delete that the server refuses or does not confirm fails the task.
* A confirmed delete reports `changed: true`, `record_uid`, and `record_title`.
* In check mode, the task reports the predicted change and does not delete the record. The server checks permissions only in a real run.
* Failures are normal task results, so `failed_when`, `ignore_errors`, and `rescue` work.
* An unknown option, or an option of the wrong type, fails the task.

{% hint style="warning" %}
The result includes the decrypted `record_title`. Task results go to the console, callback plugins, and job history. Set `no_log: true` on the task if a title is sensitive.
{% endhint %}

```yaml
---
- name: Keeper Remove
  hosts: my_hosts
  
  tasks:
    - name: Remove by UID
      keeper_remove:
        uid: RECORD UID
        
    - name: Remove by Title
      keeper_remove:
        title: RECORD TITLE
     
```

#### Required Attributes

* `uid` - A Keeper Vault record UID.
* `title` - Title of a Keeper Vault records.

Set either `uid` or `title`, but not both. A title must match exactly one record.

#### Optional Attributes

* `cache` - Accepted for compatibility and ignored. The task always reads the current vault, so an old or partial cache cannot hide a duplicate title or report a false no-op. A task that sets `cache` shows a warning. Remove the option. A loop of removals makes one full vault read for each task.

### Plugin: `keeper_create_folder`

The `keeper_create_folder` plugin creates a folder in a shared folder, or inside an existing subfolder of that shared folder. Added in v1.5.0.

The plugin is idempotent. If a folder with `folder_name` already exists directly under the target parent, the plugin returns the UID of that folder and does not create a duplicate.

```yaml
---
- name: Keeper Create Folder
  hosts: localhost
  connection: local

  tasks:
    - name: Create a new folder directly in a shared folder
      keeper_create_folder:
        shared_folder_uid: XXX
        folder_name: My New Folder
      register: my_new_folder

    - name: Create a new folder nested inside an existing subfolder
      keeper_create_folder:
        shared_folder_uid: XXX
        subfolder_uid: YYY
        folder_name: My New Nested Folder
      register: my_nested_folder
```

#### Required Attributes

* `shared_folder_uid` - The UID of the top-level shared folder. This must be a shared folder UID, not a subfolder UID.
* `folder_name` - The name of the new folder. It must be a nonblank string without leading or trailing whitespace, otherwise the task fails. Quote a name that YAML reads as a number or a boolean, for example `"2026"`. A YAML block scalar (`|` or `>`) keeps a newline at its end, so use `|-` or `>-`.

#### Optional Attributes

* `subfolder_uid` - The UID of an existing subfolder, at any depth under `shared_folder_uid`. The new folder is created in this subfolder. If omitted, the folder is created directly in the shared folder.

#### Return Values

* `changed` - `true` if the plugin created a folder, or would create one in check mode.
* `folder_uid` - The UID of the new or existing folder. In check mode, this is null for a new folder.

### Plugin: `keeper_get_folder`

The `keeper_get_folder` plugin looks up a folder that is shared to your KSM application and returns its UID. Use the UID with `keeper_create`, `keeper_create_folder`, `keeper_update_folder`, or `keeper_delete_folder`, so you do not need to copy the UID from the Vault user interface. Added in v1.5.0.

The lookup starts at `subfolder_uid` if it is set, otherwise at `shared_folder_uid`. If neither is set, the lookup starts at the top level, and `folder_name`, or the first name in `folder_path`, is the name of a shared folder. Names must match exactly, and the match is case-sensitive. If no folder matches, or more than one folder matches, the task fails. If the installed `keeper-secrets-manager-core` skips a folder that it cannot decrypt, a lookup by `folder_name` or `folder_path` also fails, even if one folder matches, because the skipped folder can have the same name. Use the UID of a readable folder instead. The plugin never returns an empty result.

```yaml
---
- name: Keeper Get Folder
  hosts: localhost
  connection: local

  tasks:
    - name: Get the UID of a subfolder in a shared folder
      keeper_get_folder:
        shared_folder_uid: XXX
        folder_name: Databases
      register: databases_folder

    - name: Create a folder in that subfolder
      keeper_create_folder:
        shared_folder_uid: XXX
        subfolder_uid: "{{ databases_folder.folder_uid }}"
        folder_name: Production

    - name: Get a nested folder by its path from a shared folder
      keeper_get_folder:
        shared_folder_uid: XXX
        folder_path: Databases/Production
      register: production_folder
```

With no `folder_name` and no `folder_path`, the plugin returns the start folder itself. This also happens when a template leaves the name out, for example with `default(omit)`. Keep this in mind before you give the result to `keeper_update_folder` or `keeper_delete_folder`.

#### Optional Attributes

* `shared_folder_uid` - The UID of a top-level shared folder. The lookup starts at this folder. This must be a shared folder UID, not a subfolder UID.
* `subfolder_uid` - The UID of an existing subfolder. The lookup starts at this folder. If `shared_folder_uid` is also set, the subfolder must be inside that shared folder, at any depth.
* `folder_name` - The exact name of a folder directly inside the start folder. If there is no start folder, the exact name of a shared folder. Do not use it with `folder_path`.
* `folder_path` - A path of folder names, for example `Databases/Production`. The lookup goes down one folder for each name. A string is split on `/`. If a folder name contains `/`, give the path as a list of names. An empty name, including a leading, trailing, or double `/`, is an error. Do not use it with `folder_name`.
* `include_subfolders` - Defaults to **False**. If **True**, the result also lists every folder below the found folder, at all depths. If the installed `keeper-secrets-manager-core` skips a folder that it cannot decrypt, the task shows a warning, and the list can miss folders below the found folder.

#### Return Values

* `folder_uid` - The UID of the folder that the lookup found.
* `folder_name` - The name of the folder.
* `parent_uid` - The UID of the parent folder. An empty string for a shared folder.
* `shared_folder_uid` - The UID of the shared folder that contains the folder. For a shared folder, its own UID.
* `subfolders` - Returned when `include_subfolders` is **True**. A list of every folder below the found folder, a parent before its children. Each item has `folder_uid`, `folder_name`, and `parent_uid`.

{% hint style="info" %}
The task result and the error messages show folder names and UIDs. To keep them out of the output and the logs, set `no_log: true` on the task. With `no_log: true`, a failed folder task shows the message "The folder operation failed. Diagnostic details are hidden because no\_log is enabled.", and the plugin hides the diagnostics of `keeper-secrets-manager-core` for that task. A failure of the task options that names no value from the task, such as a missing option or both `folder_name` and `folder_path` set, still shows its own short message.
{% endhint %}

### Plugin: `keeper_update_folder`

The `keeper_update_folder` plugin renames a folder or subfolder that is shared to your KSM application. Added in v1.5.0.

The plugin is idempotent. If the folder already has the new name, the task reports `changed: false` and sends no update. The comparison is exact and case-sensitive. The plugin can only rename a folder. It cannot move a folder to a different parent.

```yaml
---
- name: Keeper Update Folder
  hosts: localhost
  connection: local

  tasks:
    - name: Rename a folder
      keeper_update_folder:
        folder_uid: XXX
        new_folder_name: Production Databases
      register: renamed_folder

    - name: Show the old and the new name
      debug:
        msg: "Renamed {{ renamed_folder.previous_folder_name }} to {{ renamed_folder.folder_name }}"
```

A new name with a space, a tab, or a newline at the start or the end fails the task, because a later lookup of the name would not find the folder. Keeper allows two folders with the same name in the same parent folder. If the parent already has a folder with the new name, the plugin renames the folder and shows a warning. In check mode, the plugin does all of its checks and does not rename the folder.

#### Required Attributes

* `folder_uid` - The UID of the folder to rename. To get the UID from a name, use `keeper_get_folder`.
* `new_folder_name` - The new name of the folder.

#### Return Values

* `folder_uid` - The UID of the folder.
* `folder_name` - The name of the folder after the task. In check mode, the name that a real run gives the folder.
* `previous_folder_name` - The name of the folder before the task. It is the same as `folder_name` if the name did not change.

### Plugin: `keeper_delete_folder`

The `keeper_delete_folder` plugin deletes a folder or subfolder that is shared to your KSM application. Added in v1.5.0.

The plugin is idempotent. If the folder does not exist, or it is not shared to the application, the task reports `changed: false` and does not fail. By default, the plugin deletes only an empty folder. If the folder contains records or subfolders, the task fails and deletes nothing, unless `force_deletion` is **True**. If the installed `keeper-secrets-manager-core` skips a folder that it cannot decrypt, the plugin cannot count the contents of that folder and shows a warning, and the Keeper server checks whether the folder is empty. If the Keeper server does not confirm a delete, the plugin reads the folder list again. The task fails when the folder still exists or cannot be read, because the folder can still exist.

```yaml
---
- name: Keeper Delete Folder
  hosts: localhost
  connection: local

  tasks:
    - name: Delete an empty folder
      keeper_delete_folder:
        folder_uid: XXX

    - name: Delete a folder and everything in it
      keeper_delete_folder:
        folder_uid: XXX
        force_deletion: yes

    # keeper_get_folder fails if the folder does not exist, for example on a second run after the delete.
    # The failed_when keeps the play idempotent: it ignores only the "No folder named" failure.
    - name: Find a folder by name
      keeper_get_folder:
        shared_folder_uid: XXX
        folder_name: Temporary
      register: temporary_folder
      failed_when:
        - temporary_folder is failed
        - "'No folder named' not in temporary_folder.msg"

    - name: Delete the folder, if the lookup found it
      keeper_delete_folder:
        folder_uid: "{{ temporary_folder.folder_uid }}"
      when: temporary_folder.folder_uid is defined
```

In check mode, the plugin does all of its checks and does not delete the folder.

{% hint style="warning" %}
`force_deletion: yes` deletes the records and the subfolders of the folder with it. You cannot undo this delete with Ansible. Do not set `force_deletion` in `module_defaults`, because it would force every `keeper_delete_folder` task that the defaults apply to. The option is not named `force` because `keeper_copy` has a `force` option with a different meaning.
{% endhint %}

#### Required Attributes

* `folder_uid` - The UID of the folder to delete. To get the UID from a name, use `keeper_get_folder`.

#### Optional Attributes

* `force_deletion` - Defaults to **False**. If **True**, delete the folder even if it contains records or subfolders.

#### Return Values

* `folder_uid` - The UID of the folder, from the `folder_uid` option.
* `folder_name` - The name of the deleted folder. Null if the folder was not found.
* `msg` - Returned when the folder was not found. It says that nothing was deleted.

### Plugin: `keeper_password`

The `keeper_password` plugin will generate a random password. The action plugin will return the `password`.

Example:

```yaml
---
- name: Keeper Password
  hosts: my_hosts
  
  tasks:
    - name: Generate a long password
      keeper_password:
        length: 128
      register: long_password
    - name: Show long password
      debug:
        msg: "Long password {{ long_password.password }}"
        
    - name: Generate an all digit password
      keeper_password:
        length: 32
        allow_lowercase: False
        allow_uppercase: False
        allow_symbols: False
      register: digit_password
    - name: Show digit password
      debug:
        msg: "Digit password {{ digit_password.password }}"
        
    - name: Generate a PostgreSQL password (no % character)
      keeper_password:
        length: 64
        filter_characters: 
          - "%"
      register: pg_password
    - name: Show PostgreSQL password
      debug:
        msg: "PG password {{ pg_password.password }}"    
```

All parameters are optional. If no parameters are set, the defaults will be used.

* `length` - Length of password. Defaults to **64**.
* `allow_lowercase` - Defaults to **True**. If set to **False**, no lowercase letters will be used.
* `allow_uppercase` - Defaults to **True**. If set to **False**, no uppercase letters will be used.
* `allow_digits` - Defaults to **True**. If set to **False**, no digits will be used.
* `allow_symbols` - Defaults to True. If set to **False**, no symbols will be used.
* `filter_characters` - A list of characters to exclude from the password. This allows to remove characters a services will reject. For example, '%' in SQL. If not set, the password will not be filtered.

{% hint style="info" %}
Password generation will use the following symbols: "!@#$%()+;<>=?\[]{}^.,
{% endhint %}

Based of record types, certain fields maybe required. Custom fields are optional. Both fields and custom\_field are an array of values.

### Plugin: `keeper_lookup`

The `keeper_lookup` plugin retrieves a field from the Keeper vault record and inserts the value into a text string. Example:

```yaml
---
- name: Keeper Lookup
  hosts: my_hosts
  
  tasks:
    - name: Write login to file. Get record from the Keeper Vault
      copy:
        content: "My login is {{ lookup('keeper', uid='RECORD UID', field='login') }}"
        dest: "/tmp/my_login.txt"
      no_log: True
      
    - name: Using the array_index and value_key on complex values
      debug:
        msg: >-
          Second phone number is 
          {{ lookup('keeper', uid='RECORD UID', custom_field='My Phone', array_index=1, value_key='number') }}
 
```

In the example above, the first task the content of a file is created by templating the login name of a user from a Keeper record.

The second task displays as debug the second phone of number from a field with a complex value using the `array_index` and `value_key` task attributes. An `array_index` starts at 0, the next item in the array will be 1, the next is 2, a so on. The `value_key` is the name of key in a key/pair dictionary.

#### Required Attributes

* `uid` - A Keeper Vault record UID.
* `title` - Title of a Keeper Vault records.
* `notation` - Use Keeper Notation to get the field from a record.

Set exactly one of `uid` or `title`, or use `notation` alone. Setting both `uid` and `title` fails the task. Unless you use `notation`, also set exactly one of `field`, `custom_field`, `file`, or `notes`.

#### Optional Attributes

* `cache` - The record cache. Used for getting multiple records, will not update the cache.
* `field` - Get the value from the standard Keeper Vault record.
* `custom_field` - Get the value from the custom Keeper Vault record.
* `file` - Get the value from the files attach to the Keeper Vault record by file title.
* `notes` - Set to `yes` to get the notes field from the record. Notes is a singleton field, so it uses a boolean flag instead of a field name.
* `allow_array` - By default is **False**. If set to **True**, an array of values will be returned. This is needed if the field contains multiple values such as Phone numbers. If **True**, `array_index` and `value_key` will be ignored.
* `array_index` - Defaults to 0. If the field value contains multiple values, this attribute will allow you to select which item to return. The first item will have the `array_index` of 0, and the next will be 1, etc.
* `value_key` - If the field value is a complex object, this will allow you to select the key of the key/value pair to return.

#### Important Notes

* To avoid leaking secret values when using the lookup plugin, add `'no_log: True'` to the task. The stdout information will not be logged if the value is True.
* If the plugin was installed by Ansible Galaxy the longer name is required for the lookup plugin (i.e. keepersecurity.keeper\_secrets\_manager.keeper). Listing collections appears not to work with lookup plugins.
* To find out what fields and custom fields are available for a specific vault secret, use the Keeper Secrets Manager CLI "`ksm secret get -u XXXX`" command. More info [here](https://docs.keeper.io/keeperpam/secrets-manager/secrets-manager-command-line-interface/secret-command.md#secret-command).

### Plugin: `keeper_init`

The `keeper_init` plugin initialize a configuration from a one time access token. This is similar to the `keeper_ansible --keeper_token` command. The plugin accepts the following options.

* `token` - The one time access token. It's best to template this value and pass in the value.
* `filename` - The configuration file name to generate with config values. If not included, the configuration will not be created.
* `show_config` - A flag to indicate if the configuration values should be returned in the task log. By default this is `False`. Only set to True if you are unable to generate the configuration via other methods or do not have access to a generated configuration file. If True, the configuration will be logged. This might not be a problem if running the playbook via the command line, however if running via Ansible Tower to will be log file which is retained.

```yaml
---
- name: Keeper Lookup
  hosts: localhost
  connection: local
  
  tasks:
    - name: Init the one time access token
      keeper_init:
        token: "{{ keeper_token }}"
        filename: "{{ keeper_config_file }}"
        show_config: False
```

It's best not to hard code the token into the playbook since it's only good once. The token and the configuration file name can be passed into the playbook using the `extra vars`.

```bash
$ ansible-playbook my_init_playbook.yml \
  -e "keeper_token=US:XXX" \
  -e "keeper_config_file=my_keeper_config.yml"
```

The above will generate a file similar to the one below. The content of the file can be copied into a configuration file used by ansible, and optionally encrypted by `ansible-vault`.

```
keeper_app_key: +U5Ja ... 5FmXymVI=
keeper_client_id: Fokc ... WBdUPxPlBwzAKlMUgFZHqLg==
keeper_hostname: US
keeper_private_key: MIGHA ... yA7Oy
keeper_server_public_key_id: '10'
```

#### Ansible Galaxy Role

If the Keeper Secret Manager plugins were installed via Ansible Galaxy, a role called `keeper_init_token` was installed to initialize the one-time access token. This role can be used in a playbook.

```yaml
---
- name: Initialize One Time Access Token
  hosts: localhost
  connection: local
  collections: keepersecurity.keeper_secrets_manager

  roles:
    - keeper_init_token
```

The role will use the following options set via extra variables.

* `keeper_token` - Required one-time access token.
* `keeper_config_file` - Generate a file containing the configuration. If not set, no file will be created.
* `keeper_show_config` *= Default False. If set to True, it will show the config in the log if verbosity is enabled.*

Either `keeper_config_file` or `keeper_show_config` should be used, else the token will initialize and you will not be able to view the resulting configuration.

### Plugin: keeper\_info

The keeper\_info action will display information about the Keeper ansible plugin. The results include a list of record types, field types, and versions of Python modules. In order to see the results, the verbosity level needed to be set at 1 or higher.

```yaml
---
- name: Keeper Info
  hosts: localhost
  connection: local
  
  tasks:
    - name: Display Keeper Info
      keeper_info:
```

This can be used to verify custom record types are being picked up by the plugins.

### Plugin: `keeper_cleanup`

The `keeper_cleanup` plugin is used to clean up any files created by the keeper plugins. This is mainly used to delete a cache file, if you are using it. Disaster Recovey cache files are used when there are network problems as a fall back to get records. If you are running Ansible secret environment, there is no need to remove the Disaster Recovey cache. However this plugin gives you the ability to do so.

```yaml
- name: Keeper Lookup
  hosts: localhost
  connection: local
  vars:
    keeper_use_cache: True
  
  tasks:
    ... bunch of tasks
    
    - name: Remove the cache file
      keeper_cleanup:
    
```

### Plugin: `keeper_redact`

The `keeper_redact` stdout callback plugin redacts secret values from the standard output logs. It hides the values that `keeper_get`, `keeper_get_record`, and `keeper_password` return, including values with special characters, for example a multiline key. It hides a multiline value that a task prints as text or as a list of lines, with LF or CRLF line endings. It does not hide one line of the value on its own, the lines joined with another separator, a YAML dump of the lines, some of the lines, or the lines in a different order. It also hides values of four or more characters when later tasks in the same run print them. It also hides the SHA-1, MD5, and SHA-256 hashes of these values, because the built-in `copy` module prints the SHA-1 of its content. It also hides the `keeper_config`, `keeper_config_file`, `keeper_client_id`, `keeper_private_key`, `keeper_app_key`, `keeper_token`, and `keeper_record_cache_secret` variables when a task result shows them by name. It does not hide these values when a task shows them under another name, for example in the `msg` of a `debug` or `fail` task. Use `no_log: True` on such tasks. It does not redact `keeper_lookup`. It also does not redact the folder names, folder UIDs, and record titles that `keeper_remove` and the folder plugins return. It changes only what the console prints, not registered results or other callbacks, and it does not hide secrets from AWX and AAP job events. Use the `no_log: True` directive to hide the whole result of a task, including these.

{% hint style="info" %}
See [How do I keep secrets data in my playbook?](https://docs.ansible.com/ansible/latest/reference_appendices/faq.html#keep-secret-data) Using `no_log` can hide all logging from a task. This plugin is for when you just want secrets returned by the Keeper Secrets Manager plugins to be hidden/redacted.
{% endhint %}

{% hint style="info" %}
The `keeper_redact` plugin will not work with Ansible Tower since it had its own stdout callback plugin to stream the log as the job runs. Highly recommend using the `no_log` option when you do not wish show information in the log.
{% endhint %}

To use the `keeper_redact` plugin, enable it in your *ansible.cfg.*

```ini
[defaults]
stdout_callback = keeper_redact
# Use long name if install via Ansible Galaxy
# stdout_callback = keepersecurity.keeper_secrets_manager.keeper_redact
```

For example, the following task would return all the phone numbers in the custom field *MyPhoneNumbers* and place them into the variable *phone\_numbers*.

```yaml
    - name: "Get Phone Numbers"
      keeper_get:
        uid: OlLZ6JLjnyMOS3CiIPHBjw
        custom_field: MyPhoneNumbers
        allow_array: True
      register: phone_numbers
```

If the playbook was run with any verbosity, the values being placed into the variable would be displayed. This would leak the secrets to the log. If the `keeper_redact` stdout callback plugin is enabled, the values in the log would be redacted.

```bash
TASK [Get Phone Numbers] **************************************************
ok: [my_server] => {
    "value": [
        {
            "number": "****",
            "type": "****",
            "ext": "****"
        },
        {
            "region": "****",
            "number": "****",
            "ext": "****",
            "type": "****"
        }
    ],
    "changed": false
}
```

## Check Mode

Use `ansible-playbook --check`, or `check_mode: yes` on a play or task, to preview Keeper changes. These plugins do their read-only checks and report `changed` without changing the vault or writing or deleting local files: `keeper_create`, `keeper_set`, `keeper_create_folder`, `keeper_update_folder`, `keeper_delete_folder`, `keeper_remove`, and `keeper_cleanup`. `keeper_init` is skipped, because redeeming a one-time token cannot be undone.

* Use an initialized Keeper configuration for a dry run. Plugins that read the vault reject a configuration that has only a one-time token before they connect. `keeper_password`, `keeper_info`, and `keeper_cleanup` never contact the vault, so they also run with a token.
* The plugins load the configuration into memory, and they do not refresh the DR cache file in check mode.
* The `keeper` lookup follows `--check` on every ansible-core version. It follows a play or task `check_mode` keyword only on ansible-core 2.19 and later. With an older ansible-core, use `--check`, or read with `keeper_get` in a dry run.
* A new record or folder has no UID in check mode, so `record_uid` or `folder_uid` is null. An existing folder still returns its UID and `changed: false`. Skip tasks that depend on a new UID, for example with `when: created_record.record_uid is not none`. A `when: not ansible_check_mode` condition does not see a play or task `check_mode` keyword.
* An empty or null `subfolder_uid` means no subfolder. A later task that runs for real with a null UID from check mode uses the shared folder.
* `keeper_set` returns `updated: false` and `keeper_cleanup` returns `removed_ksm_cache: false` in check mode, even when they predict `changed: true`.
* A task that reports `changed: true` notifies its handlers in check mode too. A handler with `check_mode: false` makes real changes.

## Upgrading to 1.5.0

Version 1.5.0 changes how some existing tasks behave. Check each item below against your playbooks before you upgrade.

### Requirements

* ansible-core 2.15.13 or later, but not 2.17.x. Before, ansible-core 2.12.0 or later. Before, pip installed ansible-core with the package. The Python package no longer declares ansible-core as a dependency, so installing or upgrading only the Keeper package does not install, upgrade, or check it. Before you upgrade the package, install or upgrade ansible-core yourself in the same Python environment:

  ```bash
  $ python3 -m pip install -U 'ansible-core>=2.15.13,!=2.17.*'
  $ python3 -m pip show ansible-core
  ```

  `pip check` does not check the supported ansible-core range for this package.
* Python 3.9.2 or later. Before, Python 3.9 or later.
* keeper-secrets-manager-core 17.3.0 or later, keeper-secrets-manager-helper 1.1.2 or later, and certifi 2026.10.19 or later. The Python package installs them. For the Galaxy collection, install them with pip. An execution environment that installs this collection needs the same versions.
* The Tower Execution Environment now uses Python 3.12 and ansible-core 2.16.19 or later in the 2.16 series. Rebuild any image that you based on the old definition.

### Task results and handlers

* `keeper_create` and `keeper_init` now report `changed: true`. Before, they reported no change.
* `keeper_set` reports `changed: true` and `updated: true` only when it saves a new value. A task that sets the value that the record already has now saves nothing and reports `changed: false`.
* `keeper_cleanup` reports a change only when the DR cache file exists.
* `keeper_remove` reports `changed: true` for a confirmed delete, and `changed: false` when the record does not exist.
* `keeper_copy` no longer returns `checksum`, `md5sum`, or `size`, and `invocation` no longer holds `checksum`. These values come from the copied secret, so a short secret can be found from them. Remove any `when:` condition or `register` use that reads the three values. A failed `validate:` no longer returns `exit_status`, `stdout`, or `stderr`, and a failed copy no longer returns `traceback`, because the validate command reads the secret file and its output can show the content. Logs that earlier versions wrote can still hold them. Change a short secret that a `keeper_copy` task printed.
* Review `when:` conditions on these results, `changed_when`, and `notify`. Handlers now run after these tasks, and the play recap counts the change.

### keeper\_remove

* A record that does not exist, by UID or by title, now succeeds with `changed: false`. Before, the task failed. Remove `ignore_errors` or `failed_when` workarounds that only tolerated a missing record. To detect a missing record, test `changed`.
* Check mode no longer deletes records. Before, `--check` deleted them.
* An unknown option, or an option of the wrong type, now fails the task. Before, the plugin ignored it.
* A record that `keeper-secrets-manager-core` cannot read now fails the task and nothing is deleted. A removal by title also fails when the SDK could not read some record or folder.

### keeper\_set

* `keeper_set` updates one record. A `uid` that matches more than one live record now fails the task. Before, it updated the first one.
* A selection by `title` now fails when `keeper-secrets-manager-core` could not read some record or folder. Before, the title could select the wrong record. Use the `uid` of a readable record.
* A list with one item for `uid` or `title` counts as that item. A list with two or more items fails the task. Use one task for each record.

### Cache and outage behavior

* `keeper_set` and `keeper_remove` read the record from the vault. They never use the DR cache or a registered cache. During a Keeper outage, these two tasks now fail instead of using the DR cache.
* Versions 1.2.0 to 1.4.0 serialize the registered cache with pickle. Version 1.5.0 uses JSON.
* A cache that version 1.4.0 or earlier made cannot be used. A task that gets one shows a warning and reads the records from the vault. Upgrade to 1.5.0, then run `keeper_cache_records` again to make a new cache.

### keeper\_redact

* The callback hides a multiline value in `stdout`, `stderr`, and line lists, with LF or CRLF line endings.
* It does not hide one line of the value on its own, the lines joined with another separator, a YAML dump of the lines, some of the lines, or the lines in a different order. Use `no_log: true` on a task that prints or changes a multiline secret.

### Variables and files

* `keeper_verify_ssl_certs_skip` and `keeper_force_config_write` now accept only boolean values: `true`, `false`, `yes`, `no`, `on`, `off`, `y`, `n`, `t`, `f`, `1`, and `0`, in any case. Any other value, including an empty string, fails the task. Before, any non-empty text counted as true, so `-e keeper_verify_ssl_certs_skip=false` turned certificate verification off. Replace other values with a boolean.
* Configuration files that the plugin writes, and the DR cache file, now have mode 0600. Before, they had the umask mode, often 0644. If another user or service account reads these files, change its access.
* `keeper_init` fails with a clear message for a token with more than two parts. Before, it failed with an unpacking error.

## Ansible Vault Password Retrieval

You can use the Keeper Secret Manager CLI ("ksm") to provide the decryption password for your Ansible vaults. This is done using the ANSIBLE\_VAULT\_PASSWORD\_FILE environment variable or the vault\_password\_file in the ansible.cfg field to specify an executable file that will return a password.

A executable shell script can be created that returns the password using the "ksm" secret notation ([learn more](https://docs.keeper.io/keeperpam/secrets-manager/secrets-manager-command-line-interface/secret-command.md#notation) about ksm secret notation). For example, the below script will output a specific secret password for the given Record UID:

```bash
#!/bin/sh
ksm secret notation keeper://XXXX/field/password
```

Replace XXXX with the Vault Record UID. Running this script simply outputs the secret password.

To override the environmental variable "ANSIBLE\_VAULT\_PASSWORD\_FILE", execute the following, replacing /path/to/script with the location of the above script.

```bash
$ ANSIBLE_VAULT_PASSWORD_FILE=/path/to/script.sh ansible-playbook playbook_with_vault.yml
```

Now, when Ansible needs to decrypt any vaults used by `playbook_with_vault.yml`, it will execute that shell script. The shell script will retrieve the password from the Keeper Vault.

## Logging

By default, the Ansible plugins display only errors. Set `keeper_log_level` to `DEBUG`, `INFO`, `WARNING`, `ERROR`, or `CRITICAL` to change the SDK log level. The Ansible verbosity level overrides this variable. With `-v`, the plugins display SDK messages at INFO and higher. With `-vvv` or more, they display SDK messages at DEBUG and higher. With `-vv` or no verbosity option, the plugins use `keeper_log_level`.

## Troubleshooting

### \_\_NSPlaceholderDate in progress in another thread when fork() called error.

This appears to be specific to Ansible running on MacOS. While running a playbook you may get the following error:

```
objc[6763]: +[__NSPlaceholderDate initialize] may have been in progress in 
another thread when fork() was called. We cannot safely call it or ignore 
it in the fork() child process. Crashing instead. Set a breakpoint on 
objc_initializeAfterForkError to debug
```

This is known problem with Ansible. This can be fixed with the following environmental variable.

```
OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES ansible-playbook ...
```

### Missing Configuration file

```
TASK [Copy file from Keeper into the file] ********************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: Exception: Keeper Ansible error: There is no config file and the Ansible variable contain no config keys. Will not be able to connect to the Keeper server.
fatal: [localhost]: FAILED! => {"msg": "Unexpected failure during module execution.", "stdout": ""}
```

### ModuleNotFoundError: No module named 'ansible'

The Python interpreter that runs `keeper_ansible` cannot find Ansible. This error can occur even when the Keeper package installs without errors and `pip check` passes. An Ansible installation in a different interpreter or virtual environment does not fix it.

Activate the Python environment that holds the Keeper package. Then install and verify a supported engine:

```bash
$ python3 -m pip install -U 'ansible-core>=2.15.13,!=2.17.*'
$ python3 -m pip show ansible-core
$ python3 -c "import ansible, sys; print(sys.executable); print(ansible.__version__); print(ansible.__file__)"
$ python3 -m keeper_secrets_manager_ansible --help
```

Check that the version is 2.15.13 or later, is not in the 2.17 series, and supports this Python version. Installing or upgrading only the Keeper package does not fix this error.

If the `keeper_ansible` command is missing, and not the `ansible` module, run `python3 -m keeper_secrets_manager_ansible` from the correct environment, or correct the **PATH** of that environment.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.keeper.io/keeperpam/secrets-manager/integrations/ansible/ansible-plugin.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
