community.sops.sops_encrypt module – Encrypt data with sops
Note
This module is part of the community.sops collection (version 1.5.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
.
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.
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 |
|
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 |
|
The attributes the resulting filesystem object should have. To get supported flags look at the man page for chattr on the target system. This string should contain the attributes in the same order as the one displayed by lsattr. 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 content_text, content_binary, content_json and content_yaml must be specified. |
|
The data to encrypt. Must be a JSON dictionary. Exactly one of content_text, content_binary, content_json and content_yaml must be specified. |
|
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 content_text, content_binary, content_json and content_yaml must be specified. |
|
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 content_text, content_binary, content_json and content_yaml must be specified. |
|
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 unencrypted_suffix. 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 chown. 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 /usr/bin/chmod remember that modes are actually octal numbers. You must either add a leading zero so that Ansible’s YAML parser knows it is an octal number (like Giving Ansible a number without following one 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 chown. When left unspecified, it uses the current user unless you are root, in which case it can preserve the previous ownership. |
|
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
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 }}"
Collection links
Issue Tracker Repository (Sources) Submit a bug report Request a feature Communication