openssl genrsa require password in ansible script

when I run below mentioned commands to generate RSA and csr in linux prompt , its require a password (Enter pass phrase for pradeep.key) and mention there “abc” password. Please do let me know how to capture this password in ansible script. When I mention -des3 then its require the password and its mandatory part.

  1. openssl genrsa -des3 -out pradeep.key 2048
  2. openssl req -new -key pradeep.key -out pradeepcsr.csr -config set.txt
  3. openssl pkcs12 -export -out pradeep.p12 -inkey pradeep.key -in cert.pem

Generating RSA private key, 2048 bit long modulus
…+++
…+++
e is 65537 (0x10001)
Enter pass phrase for pradeep.key:
Verifying - Enter pass phrase for pradeep.key:

I mentioned below ansible script :

command: openssl genrsa
-des3
-out “/app/ex.key” 2048

command: openssl req
-new
-subj ‘/C=US/ST=Florida/L=atlanta View/O=xx/CN=abc’
-key “/app/ex.key”
-out “/app/ex.csr”

Secondly, can we do this part with any ansible module, I tried with openssl_privatekey but its not cover all above details.

Hi Pradeep,

The scenario you mentionned can be realized using only Ansible openssl
modules[1]. Note: openssl_pkcs12 is only available starting with Ansible
2.7.

Assuming you have pyopenssl, and depending on your requirements and python knowledge... you could write your own module to do this pretty easily for earlier ansible versions