|
| 1 | +--- |
| 2 | +### include/role 3 - validate challenge |
| 3 | +- name: validate challenge only if it is created or changed |
| 4 | + when: challenge is changed |
| 5 | + block: |
| 6 | + - name: Login to autodns |
| 7 | + uri: |
| 8 | + url: "https://api.autodns.com/v1/login" |
| 9 | + method: POST |
| 10 | + body_format: json |
| 11 | + body: |
| 12 | + { "context": "4", |
| 13 | + "user": "{{ dns_user }}", |
| 14 | + "password": "{{ dns_password }}" |
| 15 | + } |
| 16 | + register: login |
| 17 | + |
| 18 | + - name: add a new TXT record to the common domain |
| 19 | + uri: |
| 20 | + url: "https://api.autodns.com/v1/zone/{{ domain.zone }}/a.ns14.net" |
| 21 | + method: PATCH |
| 22 | + body_format: json |
| 23 | + body: |
| 24 | + { |
| 25 | + "origin": "{{ domain.zone }}", |
| 26 | + "resourceRecordsAdd": [ |
| 27 | + { |
| 28 | + "name": "_acme-challenge", |
| 29 | + "ttl": 60, |
| 30 | + "type": "TXT", |
| 31 | + "value": "{{ challenge['challenge_data'][domain.common_name]['dns-01']['resource_value'] }}" |
| 32 | + } |
| 33 | + ] |
| 34 | + } |
| 35 | + headers: |
| 36 | + Cookie: "{{ login.set_cookie }}" |
| 37 | + when: |
| 38 | + # only runs if the challenge is run the first time, because then there is challenge_data |
| 39 | + - challenge['challenge_data'][domain.common_name] is defined |
| 40 | + |
| 41 | + - name: add a new TXT record to the SAN domains |
| 42 | + uri: |
| 43 | + url: "https://api.autodns.com/v1/zone/{{ domain.zone }}/a.ns14.net" |
| 44 | + method: PATCH |
| 45 | + body_format: json |
| 46 | + body: |
| 47 | + { |
| 48 | + "origin": "{{ item }}", |
| 49 | + "resourceRecordsAdd": [ |
| 50 | + { |
| 51 | + "name": "_acme-challenge.{{ item }}", |
| 52 | + "ttl": 60, |
| 53 | + "type": "TXT", |
| 54 | + "value": "{{ challenge['challenge_data'][item]['dns-01']['resource_value'] }}" |
| 55 | + } |
| 56 | + ] |
| 57 | + } |
| 58 | + headers: |
| 59 | + Cookie: "{{ login.set_cookie }}" |
| 60 | + loop: "{{ domain.subject_alt_name }}" |
| 61 | + when: |
| 62 | + - domain.subject_alt_name is defined |
| 63 | + # only runs if the challenge is run the first time, because then there is challenge_data |
| 64 | + - challenge['challenge_data'][item] is defined |
| 65 | + |
| 66 | + - name: Let the challenge be validated and retrieve the cert and intermediate certificate |
| 67 | + acme_certificate: |
| 68 | + account_key_src: "{{ account_key_path }}" |
| 69 | + account_email: "{{ account_email }}" |
| 70 | + csr: "{{ csr_path }}" |
| 71 | + cert: "{{ cert_path }}" |
| 72 | + fullchain: "{{ fullchain_path }}" |
| 73 | + chain: "{{ intermediate_path }}" |
| 74 | + challenge: dns-01 |
| 75 | + force: "{{ force_renewal | default(false) }}" |
| 76 | + acme_directory: "{{ acme_directory }}" |
| 77 | + acme_version: 2 |
| 78 | + terms_agreed: true |
| 79 | + remaining_days: "{{ remaining_days }}" |
| 80 | + data: "{{ challenge }}" |
| 81 | + |
| 82 | + - name: remove created TXT record to keep DNS zone clean |
| 83 | + uri: |
| 84 | + url: "https://api.autodns.com/v1/zone/{{ domain.zone }}/a.ns14.net" |
| 85 | + method: PATCH |
| 86 | + body_format: json |
| 87 | + body: |
| 88 | + { |
| 89 | + "origin": "{{ domain.zone }}", |
| 90 | + "resourceRecordsRem": [ |
| 91 | + { |
| 92 | + "name": "_acme-challenge", |
| 93 | + "ttl": 60, |
| 94 | + "type": "TXT", |
| 95 | + "value": "{{ challenge['challenge_data'][domain.common_name]['dns-01']['resource_value'] }}" |
| 96 | + } |
| 97 | + ] |
| 98 | + } |
| 99 | + headers: |
| 100 | + Cookie: "{{ login.set_cookie }}" |
| 101 | + when: |
| 102 | + # only runs if the challenge is run the first time, because then there is challenge_data |
| 103 | + - challenge['challenge_data'][domain.common_name] is defined |
| 104 | + |
| 105 | + - name: remove created SAN TXT records to keep DNS zone clean |
| 106 | + uri: |
| 107 | + url: "https://api.autodns.com/v1/zone/{{ domain.zone }}/a.ns14.net" |
| 108 | + method: PATCH |
| 109 | + body_format: json |
| 110 | + body: |
| 111 | + { |
| 112 | + "origin": "{{ item }}", |
| 113 | + "resourceRecordsRem": [ |
| 114 | + { |
| 115 | + "name": "_acme-challenge.{{ item }}", |
| 116 | + "ttl": 60, |
| 117 | + "type": "TXT", |
| 118 | + "value": "{{ challenge['challenge_data'][item]['dns-01']['resource_value'] }}" |
| 119 | + } |
| 120 | + ] |
| 121 | + } |
| 122 | + headers: |
| 123 | + Cookie: "{{ login.set_cookie }}" |
| 124 | + loop: "{{ domain.subject_alt_name }}" |
| 125 | + when: |
| 126 | + - domain.subject_alt_name is defined |
| 127 | + # only runs if the challenge is run the first time, because then there is challenge_data |
| 128 | + - challenge['challenge_data'][item] is defined |
0 commit comments