-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Role to create and install with custom certificates #247
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
- hosts: all | ||
roles: | ||
- custom_certificates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
custom_certificates_ca_directory: /root/custom_certificates | ||
custom_certificates_ca_directory_keys: "{{ custom_certificates_ca_directory }}/private" | ||
custom_certificates_ca_directory_certs: "{{ custom_certificates_ca_directory }}/certs" | ||
custom_certificates_ca_directory_requests: "{{ custom_certificates_ca_directory }}/requests" | ||
custom_certificates_server: "{{ ansible_fqdn }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
--- | ||
- name: 'Install openssl' | ||
yum: | ||
name: openssl | ||
state: present | ||
|
||
- name: 'Create certs directory' | ||
file: | ||
path: "{{ custom_certificates_ca_directory_certs }}" | ||
state: directory | ||
mode: 0755 | ||
|
||
- name: 'Create keys directory' | ||
file: | ||
path: "{{ custom_certificates_ca_directory_keys }}" | ||
state: directory | ||
mode: 0755 | ||
|
||
- name: 'Create requests directory' | ||
file: | ||
path: "{{ custom_certificates_ca_directory_requests }}" | ||
state: directory | ||
mode: 0755 | ||
|
||
- name: 'Deploy configuration file' | ||
template: | ||
src: openssl.cnf.j2 | ||
dest: "{{ custom_certificates_ca_directory }}/openssl.cnf" | ||
owner: root | ||
group: root | ||
mode: 0644 | ||
|
||
- name: 'Create index file' | ||
file: | ||
path: "{{ custom_certificates_ca_directory }}/index.txt" | ||
state: touch | ||
owner: root | ||
group: root | ||
mode: 0644 | ||
|
||
- name: 'Ensure serial starting number' | ||
template: | ||
src: serial.j2 | ||
dest: "{{ custom_certificates_ca_directory }}/serial" | ||
force: no | ||
owner: root | ||
group: root | ||
mode: 0644 | ||
|
||
- name: 'Creating CA certificate and key' | ||
command: > | ||
openssl req -new | ||
-x509 | ||
-nodes | ||
-extensions v3_ca | ||
-config "{{ custom_certificates_ca_directory }}/openssl.cnf" | ||
-keyout "{{ custom_certificates_ca_directory_keys }}/custom_ca.key" | ||
-out "{{ custom_certificates_ca_directory_certs }}/custom_ca.crt" | ||
args: | ||
creates: "{{ custom_certificates_ca_directory_certs }}/custom_ca.crt" | ||
|
||
- name: 'Create server key' | ||
command: > | ||
openssl genrsa | ||
-out "{{ custom_certificates_ca_directory_keys }}/{{ custom_certificates_server }}.key" | ||
args: | ||
creates: "{{ custom_certificates_ca_directory_keys }}/{{ custom_certificates_server }}.key" | ||
|
||
- name: 'Create server signing request' | ||
command: > | ||
openssl req | ||
-new | ||
-config "{{ custom_certificates_ca_directory }}/openssl.cnf" | ||
-key "{{ custom_certificates_ca_directory_keys }}/{{ custom_certificates_server }}.key" | ||
-out "{{ custom_certificates_ca_directory_requests }}/{{ custom_certificates_server }}.csr" | ||
args: | ||
creates: "{{ custom_certificates_ca_directory_requests }}/{{ custom_certificates_server }}.csr" | ||
|
||
- name: 'Create server certificate' | ||
command: > | ||
openssl ca | ||
-create_serial | ||
-batch | ||
-extensions ssl_server | ||
-config "{{ custom_certificates_ca_directory }}/openssl.cnf" | ||
-in "{{ custom_certificates_ca_directory_requests }}/{{ custom_certificates_server }}.csr" | ||
-out "{{ custom_certificates_ca_directory_certs }}/{{ custom_certificates_server }}.crt" | ||
args: | ||
creates: "{{ custom_certificates_ca_directory_certs }}/{{ custom_certificates_server }}.crt" | ||
|
||
- name: 'Run installer with custom certificates' | ||
command: > | ||
foreman-installer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add |
||
--scenario katello | ||
--certs-server-cert "{{ custom_certificates_ca_directory_certs }}/{{ custom_certificates_server }}.crt" | ||
--certs-server-cert-req "{{ custom_certificates_ca_directory_requests }}/{{ custom_certificates_server }}.csr" | ||
--certs-server-key "{{ custom_certificates_ca_directory_keys }}/{{ custom_certificates_server }}.key" | ||
--certs-server-ca-cert "{{ custom_certificates_ca_directory_certs }}/custom_ca.crt" |
77 changes: 77 additions & 0 deletions
77
playbooks/roles/custom_certificates/templates/openssl.cnf.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# {{ ansible_managed }} | ||
# | ||
#--------------------------------------------------------------------------- | ||
# OpenSSL configuration file. | ||
|
||
dir = {{ custom_certificates_ca_directory }} | ||
|
||
[ ca ] | ||
default_ca = CA_default | ||
x509_extensions = v3_ca | ||
|
||
[ CA_default ] | ||
serial = $dir/serial | ||
database = $dir/index.txt | ||
new_certs_dir = $dir/certs | ||
private_key = $dir/private/custom_ca.key | ||
certificate = $dir/certs/custom_ca.crt | ||
default_md = sha256 | ||
default_days = 7300 | ||
|
||
preserve = no | ||
email_in_dn = no | ||
policy = policy_match | ||
nameopt = default_ca | ||
certopt = default_ca | ||
|
||
unique_subject = no | ||
copy_extensions = none | ||
|
||
[ policy_match ] | ||
countryName = match | ||
stateOrProvinceName = match | ||
organizationName = match | ||
organizationalUnitName = optional | ||
commonName = supplied | ||
emailAddress = optional | ||
|
||
[ req ] | ||
default_bits = 2048 | ||
default_keyfile = privkey.pem | ||
distinguished_name = req_distinguished_name | ||
req_extensions = v3_req | ||
prompt = no | ||
|
||
[ req_distinguished_name ] | ||
countryName = US | ||
stateOrProvinceName = NC | ||
localityName = Raleigh | ||
organizationName = Foreman | ||
commonName = {{ ansible_fqdn }} | ||
|
||
[ v3_ca ] | ||
basicConstraints = CA:TRUE | ||
subjectKeyIdentifier = hash | ||
authorityKeyIdentifier = keyid:always,issuer:always | ||
nsCertType = sslCA | ||
keyUsage = cRLSign, keyCertSign | ||
extendedKeyUsage = serverAuth, clientAuth | ||
|
||
[ v3_req ] | ||
basicConstraints = CA:FALSE | ||
subjectKeyIdentifier = hash | ||
extendedKeyUsage = serverAuth, clientAuth | ||
|
||
[ ssl_server ] | ||
basicConstraints = CA:FALSE | ||
nsCertType = server | ||
keyUsage = digitalSignature, keyEncipherment | ||
extendedKeyUsage = serverAuth, nsSGC, msSGC | ||
nsComment = "OpenSSL Certificate for SSL Web Server" | ||
|
||
[ ssl_client ] | ||
basicConstraints = CA:FALSE | ||
nsCertType = client | ||
keyUsage = digitalSignature, keyEncipherment | ||
extendedKeyUsage = clientAuth | ||
nsComment = "OpenSSL Certificate for SSL Client" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1000 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be
become: true
here?fatal: [centos7-katello-nightly]: FAILED! => {"changed": false, "failed": true, "msg": "There was an issue creating /root/custom_certificates as requested: [Errno 13] Permission denied: '/root/custom_certificates'", "path": "/root/custom_certificates/certs", "state": "absent"}