| 1 |
--- |
| 2 |
# Copyright (c) Ansible Project |
| 3 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 4 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 5 |
|
| 6 |
- block: |
| 7 |
- name: Generate account keys |
| 8 |
community.crypto.openssl_privatekey: |
| 9 |
path: "{{ remote_tmp_dir }}/{{ item }}.pem" |
| 10 |
type: ECC |
| 11 |
curve: secp256r1 |
| 12 |
force: true |
| 13 |
loop: "{{ account_keys }}" |
| 14 |
|
| 15 |
- name: Parse account keys (to ease debugging some test failures) |
| 16 |
community.crypto.openssl_privatekey_info: |
| 17 |
path: "{{ remote_tmp_dir }}/{{ item }}.pem" |
| 18 |
return_private_key_data: true |
| 19 |
loop: "{{ account_keys }}" |
| 20 |
|
| 21 |
vars: |
| 22 |
account_keys: |
| 23 |
- accountkey |
| 24 |
|
| 25 |
- name: Get directory |
| 26 |
community.crypto.acme_inspect: |
| 27 |
acme_directory: "{{ acme_directory_url }}" |
| 28 |
acme_version: 2 |
| 29 |
validate_certs: false |
| 30 |
method: directory-only |
| 31 |
select_crypto_backend: "{{ select_crypto_backend }}" |
| 32 |
register: directory |
| 33 |
- ansible.builtin.debug: var=directory |
| 34 |
|
| 35 |
- name: Create an account |
| 36 |
community.crypto.acme_inspect: |
| 37 |
acme_directory: "{{ acme_directory_url }}" |
| 38 |
acme_version: 2 |
| 39 |
validate_certs: false |
| 40 |
account_key_src: "{{ remote_tmp_dir }}/accountkey.pem" |
| 41 |
url: "{{ directory.directory.newAccount }}" |
| 42 |
method: post |
| 43 |
content: '{"termsOfServiceAgreed":true}' |
| 44 |
select_crypto_backend: "{{ select_crypto_backend }}" |
| 45 |
register: account_creation |
| 46 |
# account_creation.headers.location contains the account URI |
| 47 |
# if creation was successful |
| 48 |
- ansible.builtin.debug: var=account_creation |
| 49 |
|
| 50 |
- name: Get account information |
| 51 |
community.crypto.acme_inspect: |
| 52 |
acme_directory: "{{ acme_directory_url }}" |
| 53 |
acme_version: 2 |
| 54 |
validate_certs: false |
| 55 |
account_key_src: "{{ remote_tmp_dir }}/accountkey.pem" |
| 56 |
account_uri: "{{ account_creation.headers.location }}" |
| 57 |
url: "{{ account_creation.headers.location }}" |
| 58 |
method: get |
| 59 |
select_crypto_backend: "{{ select_crypto_backend }}" |
| 60 |
register: account_get |
| 61 |
- ansible.builtin.debug: var=account_get |
| 62 |
|
| 63 |
- name: Update account contacts |
| 64 |
community.crypto.acme_inspect: |
| 65 |
acme_directory: "{{ acme_directory_url }}" |
| 66 |
acme_version: 2 |
| 67 |
validate_certs: false |
| 68 |
account_key_src: "{{ remote_tmp_dir }}/accountkey.pem" |
| 69 |
account_uri: "{{ account_creation.headers.location }}" |
| 70 |
url: "{{ account_creation.headers.location }}" |
| 71 |
method: post |
| 72 |
content: '{{ account_info | to_json }}' |
| 73 |
select_crypto_backend: "{{ select_crypto_backend }}" |
| 74 |
vars: |
| 75 |
account_info: |
| 76 |
# For valid values, see |
| 77 |
# https://www.rfc-editor.org/rfc/rfc8555.html#section-7.3 |
| 78 |
contact: |
| 79 |
- mailto:[email protected] |
| 80 |
register: account_update |
| 81 |
- ansible.builtin.debug: var=account_update |
| 82 |
|
| 83 |
- name: Create certificate order |
| 84 |
community.crypto.acme_inspect: |
| 85 |
acme_directory: "{{ acme_directory_url }}" |
| 86 |
acme_version: 2 |
| 87 |
validate_certs: false |
| 88 |
account_key_src: "{{ remote_tmp_dir }}/accountkey.pem" |
| 89 |
account_uri: "{{ account_creation.headers.location }}" |
| 90 |
url: "{{ directory.directory.newOrder }}" |
| 91 |
method: post |
| 92 |
content: '{{ create_order | to_json }}' |
| 93 |
select_crypto_backend: "{{ select_crypto_backend }}" |
| 94 |
vars: |
| 95 |
create_order: |
| 96 |
# For valid values, see |
| 97 |
# https://www.rfc-editor.org/rfc/rfc8555.html#section-7.4 and |
| 98 |
# https://www.rfc-editor.org/rfc/rfc8738.html |
| 99 |
identifiers: |
| 100 |
- type: dns |
| 101 |
value: example.com |
| 102 |
- type: dns |
| 103 |
value: example.org |
| 104 |
register: new_order |
| 105 |
- ansible.builtin.debug: var=new_order |
| 106 |
|
| 107 |
- name: Get order information |
| 108 |
community.crypto.acme_inspect: |
| 109 |
acme_directory: "{{ acme_directory_url }}" |
| 110 |
acme_version: 2 |
| 111 |
validate_certs: false |
| 112 |
account_key_src: "{{ remote_tmp_dir }}/accountkey.pem" |
| 113 |
account_uri: "{{ account_creation.headers.location }}" |
| 114 |
url: "{{ new_order.headers.location }}" |
| 115 |
method: get |
| 116 |
select_crypto_backend: "{{ select_crypto_backend }}" |
| 117 |
register: order |
| 118 |
- ansible.builtin.debug: var=order |
| 119 |
|
| 120 |
- name: Get authzs for order |
| 121 |
community.crypto.acme_inspect: |
| 122 |
acme_directory: "{{ acme_directory_url }}" |
| 123 |
acme_version: 2 |
| 124 |
validate_certs: false |
| 125 |
account_key_src: "{{ remote_tmp_dir }}/accountkey.pem" |
| 126 |
account_uri: "{{ account_creation.headers.location }}" |
| 127 |
url: "{{ item }}" |
| 128 |
method: get |
| 129 |
select_crypto_backend: "{{ select_crypto_backend }}" |
| 130 |
loop: "{{ order.output_json.authorizations }}" |
| 131 |
register: authz |
| 132 |
- ansible.builtin.debug: var=authz |
| 133 |
|
| 134 |
- name: Get HTTP-01 challenge URLs |
| 135 |
ansible.builtin.set_fact: |
| 136 |
http01challenge_urls: >- |
| 137 |
{{ |
| 138 |
authz.results |
| 139 |
| map(attribute='output_json') |
| 140 |
| map(attribute='challenges') |
| 141 |
| map('selectattr', 'type', 'equalto', 'http-01') |
| 142 |
| map('first') |
| 143 |
| map(attribute='url') |
| 144 |
| list |
| 145 |
}} |
| 146 |
|
| 147 |
- name: Get HTTP-01 challenge for authz |
| 148 |
community.crypto.acme_inspect: |
| 149 |
acme_directory: "{{ acme_directory_url }}" |
| 150 |
acme_version: 2 |
| 151 |
validate_certs: false |
| 152 |
account_key_src: "{{ remote_tmp_dir }}/accountkey.pem" |
| 153 |
account_uri: "{{ account_creation.headers.location }}" |
| 154 |
url: "{{ item }}" |
| 155 |
method: get |
| 156 |
select_crypto_backend: "{{ select_crypto_backend }}" |
| 157 |
register: http01challenge |
| 158 |
loop: "{{ http01challenge_urls }}" |
| 159 |
- ansible.builtin.debug: var=http01challenge |
| 160 |
|
| 161 |
- name: Get HTTP-01 activation URLs |
| 162 |
ansible.builtin.set_fact: |
| 163 |
activation_urls: >- |
| 164 |
{{ |
| 165 |
http01challenge.results |
| 166 |
| map(attribute='output_json') |
| 167 |
| map(attribute='url') |
| 168 |
| list |
| 169 |
}} |
| 170 |
|
| 171 |
- name: Activate HTTP-01 challenge manually |
| 172 |
community.crypto.acme_inspect: |
| 173 |
acme_directory: "{{ acme_directory_url }}" |
| 174 |
acme_version: 2 |
| 175 |
validate_certs: false |
| 176 |
account_key_src: "{{ remote_tmp_dir }}/accountkey.pem" |
| 177 |
account_uri: "{{ account_creation.headers.location }}" |
| 178 |
url: "{{ item }}" |
| 179 |
method: post |
| 180 |
content: '{}' |
| 181 |
select_crypto_backend: "{{ select_crypto_backend }}" |
| 182 |
register: activation |
| 183 |
loop: "{{ activation_urls }}" |
| 184 |
- ansible.builtin.debug: var=activation |
| 185 |
|
| 186 |
- name: Get HTTP-01 challenge results |
| 187 |
community.crypto.acme_inspect: |
| 188 |
acme_directory: "{{ acme_directory_url }}" |
| 189 |
acme_version: 2 |
| 190 |
validate_certs: false |
| 191 |
account_key_src: "{{ remote_tmp_dir }}/accountkey.pem" |
| 192 |
account_uri: "{{ account_creation.headers.location }}" |
| 193 |
url: "{{ item }}" |
| 194 |
method: get |
| 195 |
select_crypto_backend: "{{ select_crypto_backend }}" |
| 196 |
register: validation_result |
| 197 |
loop: "{{ http01challenge_urls }}" |
| 198 |
until: "validation_result.output_json.status not in ['pending', 'processing']" |
| 199 |
retries: 20 |
| 200 |
delay: 1 |
| 201 |
- ansible.builtin.debug: var=validation_result |