community.crypto.gpg_keypair module – Generate or delete GPG private and public keys
Note
This module is part of the community.crypto collection (version 2.21.0).
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.crypto
.
You need further requirements to be able to use this module,
see Requirements for details.
To use it in a playbook, specify: community.crypto.gpg_keypair
.
New in community.crypto 2.20.0
Synopsis
This module allows one to generate or delete GPG private and public keys using GnuPG (gpg).
Requirements
The below requirements are needed on the host that executes this module.
gpg >= 2.1
python-dateutil >= 2.7.0
Parameters
Parameter |
Comments |
---|---|
Specifies a comment for the key’s user ID. |
|
Specifies an email for the key’s user ID. |
|
Sets the expire date for the key. If If If If If Also excepts dates in ISO formats. If left unspecified, any created GPG keys never expire. This module will fail if an unsupported format for This module will fail if This module will fail if |
|
Specifies keys to match against. Default: |
|
If This parameter does not override This parameter is ignored if Choices:
|
|
Specifies whether or not to try to install python-dateutil package if not found. |
|
For ECC keys, this specifies the curve used to generate the keys. If If This parameter is required if This parameter is ignored if This module will fail if an unsupported Choices:
|
|
For non-ECC keys, this specifies the number of bits in the key to create. If IF As per GPG’s behavior, values below the allowed ranges will be set to the respective defaults, and values above will saturate at the maximum. |
|
Specifies the type of key to create. Choices:
|
|
Specifies usage(s) for key.
If
This module will fail if an unsupported Choices:
Default: |
|
Specifies a name for the key’s user ID. |
|
Passphrase used to decrypt an existing private key or encrypt a newly generated private key. |
|
Whether the private and public keys should exist or not, taking action if the state is different from what is stated. This module will fail if This module will fail if Choices:
|
|
List of subkeys with their own respective key types, lengths, curves, and usages. Default: |
|
Similar to
This parameter is required if This parameter is ignored if This module will fail if an unsupported Choices:
|
|
Similar to If |
|
Similar to Also supports ECDH and ELG keys. Choices:
|
|
Similar to
If This module will fail if an unsupported Choices:
Default: |
Attributes
Attribute |
Support |
Description |
---|---|---|
Support: full |
Can run in |
|
Support: none |
Will return details on what has changed (or possibly needs changing in |
Notes
Note
If a user ID is provided, the module’s options are matched against all keys with said user ID.
Matched parameters only include those in which an user has specified.
If a fingerprint is provided but no user ID is provided, the module’s options are matched against the fingerprint(s).
If neither a fingerprint or user ID is provided, the module’s options are matched against all keys.
Examples
- name: Generate the default GPG keypair
community.crypto.gpg_keypair:
- name: Generate the default GPG keypair with a passphrase
community.crypto.gpg_keypair:
passphrase: '{{ passphrase }}'
- name: Generate a RSA GPG keypair with the default RSA size (2048 bits)
community.crypto.gpg_keypair:
key_type: RSA
- name: Generate a RSA GPG keypair with custom size (4096 bits)
community.crypto.gpg_keypair:
key_type: RSA
key_size: 4096
-~/.local/share/nvim/swap/ name: Generate an ECC GPG keypair
community.crypto.gpg_keypair:
key_type: EDDSA
key_curve: ed25519
- name: Generate a GPG keypair and with a subkey
community.crypto.gpg_keypair:
subkeys:
- { key_type: ECDH, key_curve: cv25519 }
- name: Generate a GPG keypair with custom user-id
community.crypto.gpg_keypair:
name: name
comment: comment
email: name@email.com
- name: Delete a GPG keypair matching a specified fingerprint
community.crypto.gpg_keypair:
state: absent
fingerprints:
- ABC123...
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
Indicates if changes were made to GPG keyring. Returned: success Sample: |
|
Fingerprint(s) of matching, created, or deleted primary key(s). Returned: success Sample: |