�
�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
Z
d d l Z d d l m
Z
d
� Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z e d k r� e � n d S( i ( t absolute_importt divisiont print_functions 1.1t metadata_versiont previewt statust communityt supported_bys�
---
module: java_cert
version_added: '2.3'
short_description: Uses keytool to import/remove key from java keystore (cacerts)
description:
- This is a wrapper module around keytool, which can be used to import/remove
certificates from a given java keystore.
options:
cert_url:
description:
- Basic URL to fetch SSL certificate from.
- One of C(cert_url) or C(cert_path) is required to load certificate.
type: str
cert_port:
description:
- Port to connect to URL.
- This will be used to create server URL:PORT.
type: int
default: 443
cert_path:
description:
- Local path to load certificate from.
- One of C(cert_url) or C(cert_path) is required to load certificate.
type: path
cert_alias:
description:
- Imported certificate alias.
- The alias is used when checking for the presence of a certificate in the keystore.
type: str
pkcs12_path:
description:
- Local path to load PKCS12 keystore from.
type: path
version_added: "2.4"
pkcs12_password:
description:
- Password for importing from PKCS12 keystore.
type: str
default: ''
version_added: "2.4"
pkcs12_alias:
description:
- Alias in the PKCS12 keystore.
type: str
version_added: "2.4"
keystore_path:
description:
- Path to keystore.
type: path
keystore_pass:
description:
- Keystore password.
type: str
required: true
keystore_create:
description:
- Create keystore if it does not exist.
type: bool
keystore_type:
description:
- Keystore type (JCEKS, JKS).
type: str
version_added: "2.8"
executable:
description:
- Path to keytool binary if not used we search in PATH for it.
type: str
default: keytool
state:
description:
- Defines action which can be either certificate import or removal.
type: str
choices: [ absent, present ]
default: present
author:
- Adam Hamsik (@haad)
sd
- name: Import SSL certificate from google.com to a given cacerts keystore
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
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 SSL certificate from google.com to a keystore, create it if it doesn't exist
java_cert:
cert_url: google.com
keystore_path: /tmp/cacerts
keystore_pass: changeit
keystore_create: yes
state: present
- name: Import a pkcs12 keystore with a specified alias, create it if it doesn't exist
java_cert:
pkcs12_path: "/tmp/importkeystore.p12"
cert_alias: default
keystore_path: /opt/wildfly/standalone/configuration/defaultkeystore.jks
keystore_pass: changeit
keystore_create: yes
state: present
- name: Import SSL certificate to JCEKS keystore
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: yes
state: present
s�
msg:
description: Output from stdout of keytool command after execution of given command.
returned: success
type: str
sample: "Module require existing keystore at keystore_path '/tmp/test/cacerts'"
rc:
description: Keytool command execution return value.
returned: success
type: int
sample: "0"
cmd:
description: Executed command to get action done.
returned: success
type: str
sample: "keytool -importcert -noprompt -keystore"
N( t
AnsibleModulec C` s | r d | Sd S( s7 Check that custom keystore is presented in parameters s -storetype '%s't ( ( t
keystore_type( ( sD /usr/lib/python2.7/site-packages/ansible/modules/system/java_cert.pyt get_keystore_type� s c C` sK d | | | | t | � f } | j | � \ } } } | d k rG t St S( sY Check if certificate with alias is present in keystore
located at keystore_path s@ %s -noprompt -list -keystore '%s' -storepass '%s' -alias '%s' %si ( R t run_commandt Truet False( t modulet
executablet
keystore_patht
keystore_passt aliasR
t test_cmdt check_rct _( ( sD /usr/lib/python2.7/site-packages/ansible/modules/system/java_cert.pyt check_cert_present� s c
C` s� t j d � } t j d � } d }
| d k r� | j d � \ } } d | | f }
| d k r� | j d d � }
t j d d |
� }
|
d
|
7}
q� n d | |
| | f } d | | | | t | � f } | j | d
t �\ } } } | j | d | d
t
�\ } } } i d d 6d | d 6} | d k rh| j d t d | d | d | d | d | � n"