mirror of
https://github.com/ansible-collections/community.crypto.git
synced 2026-05-08 22:33:53 +00:00
Improve examples: use FQCNs and always add name: to tasks (#604)
* Improve examples: use FQCNs and always add name: to tasks. * Improve formulation. Co-authored-by: Don Naro <dnaro@redhat.com> * Accidentally added a period. --------- Co-authored-by: Don Naro <dnaro@redhat.com>
This commit is contained in:
@@ -58,7 +58,7 @@ EXAMPLES = '''
|
|||||||
account_key_src: /etc/pki/cert/private/account.key
|
account_key_src: /etc/pki/cert/private/account.key
|
||||||
register: account_data
|
register: account_data
|
||||||
- name: Verify that account exists
|
- name: Verify that account exists
|
||||||
assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- account_data.exists
|
- account_data.exists
|
||||||
- name: Print account URI
|
- name: Print account URI
|
||||||
@@ -74,7 +74,7 @@ EXAMPLES = '''
|
|||||||
account_uri: "{{ acme_account_uri }}"
|
account_uri: "{{ acme_account_uri }}"
|
||||||
register: account_data
|
register: account_data
|
||||||
- name: Verify that account exists
|
- name: Verify that account exists
|
||||||
assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- account_data.exists
|
- account_data.exists
|
||||||
- name: Print account contacts
|
- name: Print account contacts
|
||||||
|
|||||||
@@ -315,14 +315,16 @@ EXAMPLES = r'''
|
|||||||
# perform the necessary steps to fulfill the challenge
|
# perform the necessary steps to fulfill the challenge
|
||||||
# for example:
|
# for example:
|
||||||
#
|
#
|
||||||
# - copy:
|
# - name: Copy http-01 challenge for sample.com
|
||||||
|
# ansible.builtin.copy:
|
||||||
# dest: /var/www/html/{{ sample_com_challenge['challenge_data']['sample.com']['http-01']['resource'] }}
|
# dest: /var/www/html/{{ sample_com_challenge['challenge_data']['sample.com']['http-01']['resource'] }}
|
||||||
# content: "{{ sample_com_challenge['challenge_data']['sample.com']['http-01']['resource_value'] }}"
|
# content: "{{ sample_com_challenge['challenge_data']['sample.com']['http-01']['resource_value'] }}"
|
||||||
# when: sample_com_challenge is changed and 'sample.com' in sample_com_challenge['challenge_data']
|
# when: sample_com_challenge is changed and 'sample.com' in sample_com_challenge['challenge_data']
|
||||||
#
|
#
|
||||||
# Alternative way:
|
# Alternative way:
|
||||||
#
|
#
|
||||||
# - copy:
|
# - name: Copy http-01 challenges
|
||||||
|
# ansible.builtin.copy:
|
||||||
# dest: /var/www/{{ item.key }}/{{ item.value['http-01']['resource'] }}
|
# dest: /var/www/{{ item.key }}/{{ item.value['http-01']['resource'] }}
|
||||||
# content: "{{ item.value['http-01']['resource_value'] }}"
|
# content: "{{ item.value['http-01']['resource_value'] }}"
|
||||||
# loop: "{{ sample_com_challenge.challenge_data | dict2items }}"
|
# loop: "{{ sample_com_challenge.challenge_data | dict2items }}"
|
||||||
@@ -354,7 +356,8 @@ EXAMPLES = r'''
|
|||||||
# perform the necessary steps to fulfill the challenge
|
# perform the necessary steps to fulfill the challenge
|
||||||
# for example:
|
# for example:
|
||||||
#
|
#
|
||||||
# - community.aws.route53:
|
# - name: Create DNS record for sample.com dns-01 challenge
|
||||||
|
# community.aws.route53:
|
||||||
# zone: sample.com
|
# zone: sample.com
|
||||||
# record: "{{ sample_com_challenge.challenge_data['sample.com']['dns-01'].record }}"
|
# record: "{{ sample_com_challenge.challenge_data['sample.com']['dns-01'].record }}"
|
||||||
# type: TXT
|
# type: TXT
|
||||||
@@ -367,7 +370,8 @@ EXAMPLES = r'''
|
|||||||
#
|
#
|
||||||
# Alternative way:
|
# Alternative way:
|
||||||
#
|
#
|
||||||
# - community.aws.route53:
|
# - name: Create DNS records for dns-01 challenges
|
||||||
|
# community.aws.route53:
|
||||||
# zone: sample.com
|
# zone: sample.com
|
||||||
# record: "{{ item.key }}"
|
# record: "{{ item.key }}"
|
||||||
# type: TXT
|
# type: TXT
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ EXAMPLES = '''
|
|||||||
- /etc/ca-certificates/
|
- /etc/ca-certificates/
|
||||||
register: www_ansible_com
|
register: www_ansible_com
|
||||||
- name: Write root certificate to disk
|
- name: Write root certificate to disk
|
||||||
copy:
|
ansible.builtin.copy:
|
||||||
dest: /etc/ssl/csr/www.ansible.com-root.pem
|
dest: /etc/ssl/csr/www.ansible.com-root.pem
|
||||||
content: "{{ www_ansible_com.root }}"
|
content: "{{ www_ansible_com.root }}"
|
||||||
|
|
||||||
@@ -98,11 +98,11 @@ EXAMPLES = '''
|
|||||||
- /etc/ca-certificates/
|
- /etc/ca-certificates/
|
||||||
register: www_ansible_com
|
register: www_ansible_com
|
||||||
- name: Write complete chain to disk
|
- name: Write complete chain to disk
|
||||||
copy:
|
ansible.builtin.copy:
|
||||||
dest: /etc/ssl/csr/www.ansible.com-completechain.pem
|
dest: /etc/ssl/csr/www.ansible.com-completechain.pem
|
||||||
content: "{{ ''.join(www_ansible_com.complete_chain) }}"
|
content: "{{ ''.join(www_ansible_com.complete_chain) }}"
|
||||||
- name: Write root chain (intermediates and root) to disk
|
- name: Write root chain (intermediates and root) to disk
|
||||||
copy:
|
ansible.builtin.copy:
|
||||||
dest: /etc/ssl/csr/www.ansible.com-rootchain.pem
|
dest: /etc/ssl/csr/www.ansible.com-rootchain.pem
|
||||||
content: "{{ ''.join(www_ansible_com.chain) }}"
|
content: "{{ ''.join(www_ansible_com.chain) }}"
|
||||||
'''
|
'''
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ EXAMPLES = '''
|
|||||||
register: cert
|
register: cert
|
||||||
|
|
||||||
- name: How many days until cert expires
|
- name: How many days until cert expires
|
||||||
debug:
|
ansible.builtin.debug:
|
||||||
msg: "cert expires in: {{ expire_days }} days."
|
msg: "cert expires in: {{ expire_days }} days."
|
||||||
vars:
|
vars:
|
||||||
expire_days: "{{ (( cert.not_after | to_datetime('%Y%m%d%H%M%SZ')) - (ansible_date_time.iso8601 | to_datetime('%Y-%m-%dT%H:%M:%SZ')) ).days }}"
|
expire_days: "{{ (( cert.not_after | to_datetime('%Y%m%d%H%M%SZ')) - (ansible_date_time.iso8601 | to_datetime('%Y-%m-%dT%H:%M:%SZ')) ).days }}"
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ EXAMPLES = r'''
|
|||||||
register: result
|
register: result
|
||||||
|
|
||||||
- name: Dump information
|
- name: Dump information
|
||||||
debug:
|
ansible.builtin.debug:
|
||||||
var: result
|
var: result
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,8 @@ EXAMPLES = r'''
|
|||||||
privatekey_path: /etc/ssl/private/ansible.com.pem
|
privatekey_path: /etc/ssl/private/ansible.com.pem
|
||||||
common_name: www.ansible.com
|
common_name: www.ansible.com
|
||||||
register: result
|
register: result
|
||||||
- debug:
|
- name: Print CSR
|
||||||
|
ansible.builtin.debug:
|
||||||
var: result.csr
|
var: result.csr
|
||||||
|
|
||||||
- name: Generate an OpenSSL Certificate Signing Request with an inline CSR
|
- name: Generate an OpenSSL Certificate Signing Request with an inline CSR
|
||||||
|
|||||||
@@ -69,11 +69,13 @@ EXAMPLES = r'''
|
|||||||
register: output
|
register: output
|
||||||
no_log: true # make sure that private key data is not accidentally revealed in logs!
|
no_log: true # make sure that private key data is not accidentally revealed in logs!
|
||||||
- name: Show generated key
|
- name: Show generated key
|
||||||
debug:
|
ansible.builtin.debug:
|
||||||
msg: "{{ output.privatekey }}"
|
msg: "{{ output.privatekey }}"
|
||||||
# DO NOT OUTPUT KEY MATERIAL TO CONSOLE OR LOGS IN PRODUCTION!
|
# DO NOT OUTPUT KEY MATERIAL TO CONSOLE OR LOGS IN PRODUCTION!
|
||||||
|
|
||||||
- block:
|
|
||||||
|
- name: Generate or update a Mozilla sops encrypted key
|
||||||
|
block:
|
||||||
- name: Update sops-encrypted key with the community.sops collection
|
- name: Update sops-encrypted key with the community.sops collection
|
||||||
community.crypto.openssl_privatekey_pipe:
|
community.crypto.openssl_privatekey_pipe:
|
||||||
content: "{{ lookup('community.sops.sops', 'private_key.pem.sops') }}"
|
content: "{{ lookup('community.sops.sops', 'private_key.pem.sops') }}"
|
||||||
@@ -88,7 +90,7 @@ EXAMPLES = r'''
|
|||||||
when: output is changed
|
when: output is changed
|
||||||
always:
|
always:
|
||||||
- name: Make sure that output (which contains the private key) is overwritten
|
- name: Make sure that output (which contains the private key) is overwritten
|
||||||
set_fact:
|
ansible.builtin.set_fact:
|
||||||
output: ''
|
output: ''
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ EXAMPLES = r'''
|
|||||||
register: verify
|
register: verify
|
||||||
|
|
||||||
- name: Make sure the signature is valid
|
- name: Make sure the signature is valid
|
||||||
assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- verify.valid
|
- verify.valid
|
||||||
'''
|
'''
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ EXAMPLES = r'''
|
|||||||
register: verify
|
register: verify
|
||||||
|
|
||||||
- name: Make sure the signature is valid
|
- name: Make sure the signature is valid
|
||||||
assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- verify.valid
|
- verify.valid
|
||||||
'''
|
'''
|
||||||
|
|||||||
@@ -175,7 +175,8 @@ EXAMPLES = r'''
|
|||||||
path: /etc/ssl/csr/ansible.com.key
|
path: /etc/ssl/csr/ansible.com.key
|
||||||
register: result_privatekey
|
register: result_privatekey
|
||||||
|
|
||||||
- assert:
|
- name: Check conditions on certificate, CSR, and private key
|
||||||
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
# When private key was specified for assertonly, this was checked:
|
# When private key was specified for assertonly, this was checked:
|
||||||
- result.public_key == result_privatekey.public_key
|
- result.public_key == result_privatekey.public_key
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ EXAMPLES = r'''
|
|||||||
register: result
|
register: result
|
||||||
|
|
||||||
- name: Validate that certificate is valid tomorrow, but not in three weeks
|
- name: Validate that certificate is valid tomorrow, but not in three weeks
|
||||||
assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- result.valid_at.point_1 # valid in one day
|
- result.valid_at.point_1 # valid in one day
|
||||||
- not result.valid_at.point_2 # not valid in three weeks
|
- not result.valid_at.point_2 # not valid in three weeks
|
||||||
|
|||||||
Reference in New Issue
Block a user