community.sops.sops_encrypt module – Encrypt data with SOPS
Note
This module is part of the community.sops collection (version 2.0.0).
You might already have this collection installed if you are using the ansible
package.
It is not included in ansible-core
.
To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install community.sops
.
You need further requirements to be able to use this module,
see Requirements for details.
To use it in a playbook, specify: community.sops.sops_encrypt
.
New in community.sops 0.1.0
Synopsis
Allows to encrypt binary data (Base64 encoded), text data, JSON or YAML data with SOPS.
Requirements
The below requirements are needed on the host that executes this module.
A binary executable
sops
(https://github.com/getsops/sops) must exist either inPATH
or configured assops_binary
.
Parameters
Parameter |
Comments |
---|---|
Age fingerprints to use. This corresponds to the SOPS |
|
One or more age private keys that can be used to decrypt encrypted files. Will be set as the Requires SOPS 3.7.1+. |
|
The file containing the age private keys that SOPS can use to decrypt encrypted files. Will be set as the By default, SOPS looks for Requires SOPS 3.7.0+. |
|
The attributes the resulting filesystem object should have. To get supported flags look at the man page for This string should contain the attributes in the same order as the one displayed by The |
|
The AWS access key ID to use for requests to AWS. Sets the environment variable |
|
The AWS profile to use for requests to AWS. This corresponds to the SOPS |
|
The AWS secret access key to use for requests to AWS. Sets the environment variable |
|
The AWS session token to use for requests to AWS. Sets the environment variable |
|
Azure Key Vault URLs to use. This corresponds to the SOPS |
|
Path to the SOPS configuration file. If not set, SOPS will recursively search for the config file starting at the file that is encrypted or decrypted. This corresponds to the SOPS |
|
The data to encrypt. Must be Base64 encoded binary data. Please note that the module might not be idempotent if the data can be parsed as JSON or YAML. Exactly one of |
|
The data to encrypt. Must be a JSON dictionary. Exactly one of |
|
The data to encrypt. Must be a Unicode text. Please note that the module might not be idempotent if the text can be parsed as JSON or YAML. Exactly one of |
|
The data to encrypt. Must be a YAML dictionary. Please note that Ansible only allows to pass data that can be represented as a JSON dictionary. Exactly one of |
|
Tell SOPS to use local key service. This corresponds to the SOPS Choices:
|
|
Set the encrypted key suffix. When specified, only keys matching the regular expression will be encrypted. This corresponds to the SOPS |
|
Override the encrypted key suffix. When set to an empty string, all keys will be encrypted that are not explicitly marked by This corresponds to the SOPS |
|
List of KMS encryption context pairs of format This corresponds to the SOPS |
|
Force rewriting the encrypted file. Choices:
|
|
GCP KMS resource IDs to use. This corresponds to the SOPS |
|
Name of the group that should own the filesystem object, as would be fed to When left unspecified, it uses the current group of the current user unless you are root, in which case it can preserve the previous ownership. |
|
HashiCorp Vault key URIs to use. For example, This corresponds to the SOPS |
|
Specify key services to use next to the local one. A key service must be specified in the form This corresponds to the SOPS |
|
List of KMS ARNs to use. This corresponds to the SOPS |
|
The permissions the resulting filesystem object should have. For those used to Giving Ansible a number without following either of these rules will end up with a decimal number which will have unexpected results. As of Ansible 1.8, the mode may be specified as a symbolic mode (for example, If If Specifying |
|
Name of the user that should own the filesystem object, as would be fed to When left unspecified, it uses the current user unless you are root, in which case it can preserve the previous ownership. Specifying a numeric username will be assumed to be a user ID and not a username. Avoid numeric usernames to avoid this confusion. |
|
The SOPS encrypt file. |
|
PGP fingerprints to use. This corresponds to the SOPS |
|
The level part of the SELinux filesystem object context. This is the MLS/MCS attribute, sometimes known as the When set to |
|
The role part of the SELinux filesystem object context. When set to |
|
The type part of the SELinux filesystem object context. When set to |
|
The user part of the SELinux filesystem object context. By default it uses the When set to |
|
The number of distinct keys required to retrieve the data key with Shamir’s Secret Sharing. If not set here and in the SOPS config file, will default to This corresponds to the SOPS |
|
Path to the SOPS binary. By default uses |
|
Set the unencrypted key suffix. When specified, only keys matching the regular expression will be left unencrypted. This corresponds to the SOPS |
|
Override the unencrypted key suffix. This corresponds to the SOPS |
|
Influence when to use atomic operation to prevent data corruption or inconsistent reads from the target filesystem object. By default this module uses atomic operations to prevent data corruption or inconsistent reads from the target filesystem objects, but sometimes systems are configured or just broken in ways that prevent this. One example is docker mounted filesystem objects, which cannot be updated atomically from inside the container and can only be written in an unsafe manner. This option allows Ansible to fall back to unsafe methods of updating filesystem objects when atomic operations fail (however, it doesn’t force Ansible to perform unsafe writes). IMPORTANT! Unsafe writes are subject to race conditions and can lead to data corruption. Choices:
|
Attributes
Attribute |
Support |
Description |
---|---|---|
Support: full |
Can run in |
|
Support: none |
Will return details on what has changed (or possibly needs changing in |
|
Support: full |
Uses Ansible’s strict file operation functions to ensure proper permissions and avoid data corruption. |
See Also
See also
- community.sops.sops lookup plugin
The sops lookup can be used decrypt SOPS-encrypted files.
Examples
- name: Encrypt a secret text
community.sops.sops_encrypt:
path: text-data.sops
content_text: This is a secret text.
- name: Encrypt the contents of a file
community.sops.sops_encrypt:
path: binary-data.sops
content_binary: "{{ lookup('ansible.builtin.file', '/path/to/file', rstrip=false) | b64encode }}"
- name: Encrypt some datastructure as YAML
community.sops.sops_encrypt:
path: stuff.sops.yaml
content_yaml: "{{ result }}"