
See https://github.com/ansible/ansible/issues/73654 Change-Id: I949a17a8e77e96b6933e625914ea337eb94e53c2
106 lines
3.2 KiB
YAML
106 lines
3.2 KiB
YAML
---
|
|
# Copyright 2018, Rackspace US, Inc.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
# We set the python interpreter to the ansible runtime venv if
|
|
# the delegation is to localhost so that we get access to the
|
|
# appropriate python libraries in that venv. If the delegation
|
|
# is to another host, we assume that it is accessible by the
|
|
# system python instead.
|
|
|
|
- name: Install ssl packages (centos)
|
|
package:
|
|
name:
|
|
- gnutls-utils
|
|
state: present
|
|
when:
|
|
- ansible_facts['distribution'] == "CentOS"
|
|
|
|
- name: Install ssl packages (ubuntu)
|
|
package:
|
|
name:
|
|
- gnutls-bin
|
|
state: present
|
|
when:
|
|
- ansible_facts['pkg_mgr'] == 'apt'
|
|
|
|
- name: Create certificate directories
|
|
file:
|
|
path: "{{ item.path }}"
|
|
state: directory
|
|
mode: "{{ item.mode }}"
|
|
owner: root
|
|
with_items:
|
|
- { path: "{{ test_cert_dir }}", mode: '0755' }
|
|
- { path: "{{ test_cert_dir }}/newcerts", mode: '0750'}
|
|
- { path: "{{ test_cert_dir }}/private", mode: '0750'}
|
|
|
|
# set up openssl for use
|
|
- name: Touch index.txt
|
|
file:
|
|
path: "{{ test_cert_dir }}/index.txt"
|
|
state: touch
|
|
mode: 0755
|
|
|
|
- name: Init serial
|
|
copy:
|
|
content: "01"
|
|
dest: "{{ test_cert_dir }}/serial"
|
|
force: no
|
|
|
|
- name: Generate openssl.conf
|
|
template:
|
|
src: "openssl.conf.j2"
|
|
dest: "{{ test_cert_dir }}/openssl.cnf"
|
|
mode: 0440
|
|
|
|
# Create certificate authority key and cert
|
|
- name: Create the CA private key
|
|
command: openssl genrsa -aes256 -passout pass:'secrete' -out {{ test_cert_dir }}/cakey.pem 4096
|
|
args:
|
|
chdir: "{{ test_cert_dir }}"
|
|
creates: "{{ test_cert_dir }}/cakey.pem"
|
|
|
|
# ansible's openssl_certificate can't create X509 extensions
|
|
# but you need CA: true in Basic Constraints to have a CA cert
|
|
- name: Create CA certificate
|
|
command: >
|
|
openssl req -x509 -passin pass:'secrete' -new -nodes -key {{ test_cert_dir }}/cakey.pem \
|
|
-config {{ test_cert_dir }}/openssl.cnf \
|
|
-subj "/C=US/ST=Denial/L=Nowhere/O=Dis/CN=www.example.com" \
|
|
-days 1825 \
|
|
-out {{ test_cert_dir }}/ca.pem
|
|
args:
|
|
chdir: "{{ test_cert_dir }}"
|
|
creates: "{{ test_cert_dir }}/ca.pem"
|
|
|
|
# Create server key and certificate
|
|
- name: Create server cert RSA and CSR
|
|
command: >
|
|
openssl req -new -newkey rsa:4096 -nodes \
|
|
-keyout {{ test_cert_dir }}/server.key \
|
|
-out {{ test_cert_dir }}/server.csr \
|
|
-subj "/C=US/ST=Denial/L=Nowhere/O=Dis/CN=www.example.com"
|
|
args:
|
|
chdir: "{{ test_cert_dir }}"
|
|
creates: "{{ test_cert_dir }}/server.csr"
|
|
|
|
- name: Create server certificate
|
|
command: >
|
|
openssl ca -passin pass:'secrete' -config {{ test_cert_dir }}/openssl.cnf \
|
|
-in server.csr -days 1825 -out server.pem -batch
|
|
args:
|
|
chdir: "{{ test_cert_dir }}"
|
|
creates: "{{ test_cert_dir }}/server.pem"
|