community / community.general / 8.5.0 / module / java_cert Uses keytool to import/remove certificate to/from java keystore (cacerts) Authors: Adam Hamsik (@haad)community.general.java_cert (8.5.0) — module
Install with ansible-galaxy collection install community.general:==8.5.0
collections: - name: community.general version: 8.5.0
This is a wrapper module around keytool, which can be used to import certificates and optionally private keys to a given java keystore, or remove them from it.
- name: Import SSL certificate from google.com to a given cacerts keystore community.general.java_cert: cert_url: google.com cert_port: 443 keystore_path: /usr/lib/jvm/jre7/lib/security/cacerts keystore_pass: changeit state: present
- name: Remove certificate with given alias from a keystore community.general.java_cert: cert_url: google.com keystore_path: /usr/lib/jvm/jre7/lib/security/cacerts keystore_pass: changeit executable: /usr/lib/jvm/jre7/bin/keytool state: absent
- name: Import trusted CA from SSL certificate community.general.java_cert: cert_path: /opt/certs/rootca.crt keystore_path: /tmp/cacerts keystore_pass: changeit keystore_create: true state: present cert_alias: LE_RootCA trust_cacert: true
- name: Import SSL certificate from google.com to a keystore, create it if it doesn't exist community.general.java_cert: cert_url: google.com keystore_path: /tmp/cacerts keystore_pass: changeit keystore_create: true state: present
- name: Import a pkcs12 keystore with a specified alias, create it if it doesn't exist community.general.java_cert: pkcs12_path: "/tmp/importkeystore.p12" cert_alias: default keystore_path: /opt/wildfly/standalone/configuration/defaultkeystore.jks keystore_pass: changeit keystore_create: true state: present
- name: Import SSL certificate to JCEKS keystore community.general.java_cert: pkcs12_path: "/tmp/importkeystore.p12" pkcs12_alias: default pkcs12_password: somepass cert_alias: default keystore_path: /opt/someapp/security/keystore.jceks keystore_type: "JCEKS" keystore_pass: changeit keystore_create: true state: present
mode: description: - The permissions the resulting filesystem object should have. - For those used to I(/usr/bin/chmod) remember that modes are actually octal numbers. You must give Ansible enough information to parse them correctly. For consistent results, quote octal numbers (for example, V('644') or V('1777')) so Ansible receives a string and can do its own conversion from string into number. Adding a leading zero (for example, V(0755)) works sometimes, but can fail in loops and some other circumstances. - 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, V(u+rwx) or V(u=rw,g=r,o=r)). - If O(mode) is not specified and the destination filesystem object B(does not) exist, the default C(umask) on the system will be used when setting the mode for the newly created filesystem object. - If O(mode) is not specified and the destination filesystem object B(does) exist, the mode of the existing filesystem object will be used. - Specifying O(mode) is the best way to ensure filesystem objects are created with the correct permissions. See CVE-2020-1736 for further details. type: raw version_added: 8.5.0 version_added_collection: community.general group: description: - Name of the group that should own the filesystem object, as would be fed to I(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. type: str version_added: 8.5.0 version_added_collection: community.general owner: description: - Name of the user that should own the filesystem object, as would be fed to I(chown). - 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. type: str version_added: 8.5.0 version_added_collection: community.general state: choices: - absent - present default: present description: - Defines action which can be either certificate import or removal. - When state is present, the certificate will always idempotently be inserted into the keystore, even if there already exists a cert alias that is different. type: str serole: description: - The role part of the SELinux filesystem object context. - When set to V(_default), it will use the C(role) portion of the policy if available. type: str version_added: 8.5.0 version_added_collection: community.general setype: description: - The type part of the SELinux filesystem object context. - When set to V(_default), it will use the C(type) portion of the policy if available. type: str version_added: 8.5.0 version_added_collection: community.general seuser: description: - The user part of the SELinux filesystem object context. - By default it uses the V(system) policy, where applicable. - When set to V(_default), it will use the C(user) portion of the policy if available. type: str version_added: 8.5.0 version_added_collection: community.general selevel: description: - The level part of the SELinux filesystem object context. - This is the MLS/MCS attribute, sometimes known as the C(range). - When set to V(_default), it will use the C(level) portion of the policy if available. type: str version_added: 8.5.0 version_added_collection: community.general cert_url: description: - Basic URL to fetch SSL certificate from. - Exactly one of O(cert_url), O(cert_path), or O(pkcs12_path) is required to load certificate. type: str cert_path: description: - Local path to load certificate from. - Exactly one of O(cert_url), O(cert_path), or O(pkcs12_path) is required to load certificate. type: path cert_port: default: 443 description: - Port to connect to URL. - This will be used to create server URL:PORT. type: int attributes: aliases: - attr description: - The attributes the resulting filesystem object should have. - To get supported flags look at the man page for I(chattr) on the target system. - This string should contain the attributes in the same order as the one displayed by I(lsattr). - The C(=) operator is assumed as default, otherwise C(+) or C(-) operators need to be included in the string. type: str version_added: 8.5.0 version_added_collection: community.general cert_alias: description: - Imported certificate alias. - The alias is used when checking for the presence of a certificate in the keystore. type: str executable: default: keytool description: - Path to keytool binary if not used we search in PATH for it. type: str pkcs12_path: description: - Local path to load PKCS12 keystore from. - Unlike O(cert_url) and O(cert_path), the PKCS12 keystore embeds the private key matching the certificate, and is used to import both the certificate and its private key into the java keystore. - Exactly one of O(cert_url), O(cert_path), or O(pkcs12_path) is required to load certificate. type: path pkcs12_alias: description: - Alias in the PKCS12 keystore. type: str trust_cacert: default: false description: - Trust imported cert as CAcert. type: bool version_added: 0.2.0 version_added_collection: community.general keystore_pass: description: - Keystore password. required: true type: str keystore_path: description: - Path to keystore. type: path keystore_type: description: - Keystore type (JCEKS, JKS). type: str unsafe_writes: default: false description: - 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. type: bool version_added: 8.5.0 version_added_collection: community.general keystore_create: default: false description: - Create keystore if it does not exist. type: bool pkcs12_password: description: - Password for importing from PKCS12 keystore. type: str
cmd: description: Executed command to get action done. returned: success sample: keytool -importcert -noprompt -keystore type: str msg: description: Output from stdout of keytool command after execution of given command. returned: success sample: Module require existing keystore at keystore_path '/tmp/test/cacerts' type: str rc: description: Keytool command execution return value. returned: success sample: '0' type: int