Ansible – Copy file from node to remote

In this post, I will show you how to read a certificate request file and extract some informations. In the current case, the information is the Subject Alternate Name. If SAN have been specified in the CSR, it will be shown in the message output using a custom XML format.

The module openssl_csr_info is quite new. This module has been introduced with the latest Ansible version (2.8). The documentation is available here.

The following playbook has been tested with a 2048 bits CSR file.

- name: Read CSR content
  hosts: mynode
  - name: Read CSR with openssl Ansible module (Ansible 2.8 version min required)
      path: /tmp/myrequest.csr
    register: result

  - name: If SAN exits (previous step output result > 1) print SAN entries using XML
      msg: 'MYSANVAR=<SANEntries>
                             {% for result in (result.subject_alt_name | difference(["DNS:"+result.subject["commonName"],"DNS:2048"]))  %}
                                       <SubjectAltName>{{ result.split(":")[1] }}</SubjectAltName>
                             {% endfor %}
    when: result.subject_alt_name | difference(["DNS:"+result.subject["commonName"],"DNS:2048"]) | length > 0

Ansible – Read Certificate request file with the module openssl_csr_info

Leave a Reply

Your email address will not be published.