�
�Udac @` s d d l m Z m Z m Z e Z i d d 6d g d 6d d 6Z d Z d Z d
Z d d l
m Z d d l Z d d l
Z
d
� Z d � Z e d � Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z d e f d � � YZ d � Z e d k re � n d S( i ( t absolute_importt divisiont print_functions 1.1t metadata_versiont previewt statust communityt supported_bysL
---
module: java_keystore
short_description: Create or delete a Java keystore in JKS format.
description:
- Create or delete a Java keystore in JKS format for a given certificate.
version_added: "2.7"
options:
name:
description:
- Name of the certificate.
required: true
certificate:
description:
- Certificate that should be used to create the key store.
required: true
private_key:
description:
- Private key that should be used to create the key store.
required: true
password:
description:
- Password that should be used to secure the key store.
required: true
dest:
description:
- Absolute path where the jks should be generated.
required: true
owner:
description:
- Name of the user that should own jks file.
required: false
group:
description:
- Name of the group that should own jks file.
required: false
mode:
description:
- Mode the file should be.
required: false
force:
description:
- Key store will be created even if it already exists.
required: false
type: bool
default: 'no'
requirements: [openssl, keytool]
author: Guillaume Grossetie (@Mogztter)
s{
# Create a key store for the given certificate (inline)
- java_keystore:
name: example
certificate: |
-----BEGIN CERTIFICATE-----
h19dUZ2co2fI/ibYiwxWk4aeNE6KWvCaTQOMQ8t6Uo2XKhpL/xnjoAgh1uCQN/69
MG+34+RhUWzCfdZH7T8/qDxJw2kEPKluaYh7KnMsba+5jHjmtzix5QIDAQABo4IB
-----END CERTIFICATE-----
private_key: |
-----BEGIN RSA PRIVATE KEY-----
DBVFTEVDVFJJQ0lURSBERSBGUkFOQ0UxFzAVBgNVBAsMDjAwMDIgNTUyMDgxMzE3
GLlDNMw/uHyME7gHFsqJA7O11VY6O5WQ4IDP3m/s5ZV6s+Nn6Lerz17VZ99
-----END RSA PRIVATE KEY-----
password: changeit
dest: /etc/security/keystore.jks
# Create a key store for the given certificate (lookup)
- java_keystore:
name: example
certificate: "{{lookup('file', '/path/to/certificate.crt') }}"
private_key: "{{lookup('file', '/path/to/private.key') }}"
password: changeit
dest: /etc/security/keystore.jks
s
msg:
description: Output from stdout of keytool/openssl command after execution of given command or an error.
returned: changed and failure
type: str
sample: "Unable to find the current certificate fingerprint in ..."
rc:
description: keytool/openssl command execution return value
returned: changed and failure
type: int
sample: "0"
cmd:
description: Executed command to get action done
returned: changed and failure
type: str
sample: "openssl x509 -noout -in /tmp/cert.crt -fingerprint -sha256"
( t
AnsibleModuleNc C` s� d | | f } t | | � \ } } } | d k rV | j d | d | d | d | � St j d | � } | s� | j d d | d | d | � S| j d � S(
Ns* %s x509 -noout -in %s -fingerprint -sha256i t msgt errt rct cmds =([\w:]+)s8 Unable to find the current certificate fingerprint in %si ( t run_commandst fail_jsont ret searcht group( t modulet openssl_bint certificate_patht# current_certificate_fingerprint_cmdR t# current_certificate_fingerprint_outt# current_certificate_fingerprint_errt current_certificate_match( ( sH /usr/lib/python2.7/site-packages/ansible/modules/system/java_keystore.pyt read_certificate_fingerprintv s
c
C` s� d | | | | f } t | | � \ } } } | d k rs d | | k rl | j d | d | d | d | � Sd SnE t j d | � } | s� | j d d | d | d | � S| j d
� Sd S( Ns6 %s -list -alias '%s' -keystore '%s' -storepass '%s' -vi s= keytool error: java.lang.Exception: Alias <%s> does not existR R
R R s SHA256: ([\w:]+)s7 Unable to find the stored certificate fingerprint in %si ( R
R t NoneR R R (
R t keytool_bint aliast
keystore_patht keystore_passwordt"