|  | 
|  | 1 | +# Copyright 2025 Cloudera, Inc. | 
|  | 2 | +# | 
|  | 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 4 | +# you may not use this file except in compliance with the License. | 
|  | 5 | +# You may obtain a copy of the License at | 
|  | 6 | +# | 
|  | 7 | +#     https://www.apache.org/licenses/LICENSE-2.0 | 
|  | 8 | +# | 
|  | 9 | +# Unless required by applicable law or agreed to in writing, software | 
|  | 10 | +# distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 12 | +# See the License for the specific language governing permissions and | 
|  | 13 | +# limitations under the License. | 
|  | 14 | + | 
|  | 15 | +--- | 
|  | 16 | + | 
|  | 17 | +- name: Gather host distribution details | 
|  | 18 | +  ansible.builtin.setup: | 
|  | 19 | +    gather_subset: distribution | 
|  | 20 | + | 
|  | 21 | +- name: Load distribution variables | 
|  | 22 | +  ansible.builtin.include_vars: "{{ item }}" | 
|  | 23 | +  with_first_found: | 
|  | 24 | +    - "{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_version'] }}.yml" | 
|  | 25 | +    - "{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_major_version'] }}.yml" | 
|  | 26 | +    - "{{ ansible_facts['distribution'] }}.yml" | 
|  | 27 | +    - "{{ ansible_facts['os_family'] }}-{{ ansible_facts['distribution_version'] }}.yml" | 
|  | 28 | +    - "{{ ansible_facts['os_family'] }}-{{ ansible_facts['distribution_major_version'] }}.yml" | 
|  | 29 | +    - "{{ ansible_facts['os_family'] }}.yml" | 
|  | 30 | +    - "default.yml" | 
|  | 31 | + | 
|  | 32 | +- name: Run distribution pre-tasks | 
|  | 33 | +  ansible.builtin.include_tasks: "{{ item }}" | 
|  | 34 | +  with_first_found: | 
|  | 35 | +    - "{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_version'] }}-pre.yml" | 
|  | 36 | +    - "{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_major_version'] }}-pre.yml" | 
|  | 37 | +    - "{{ ansible_facts['distribution'] }}-pre.yml" | 
|  | 38 | +    - "{{ ansible_facts['os_family'] }}-{{ ansible_facts['distribution_version'] }}-pre.yml" | 
|  | 39 | +    - "{{ ansible_facts['os_family'] }}-{{ ansible_facts['distribution_major_version'] }}-pre.yml" | 
|  | 40 | +    - "{{ ansible_facts['os_family'] }}-pre.yml" | 
|  | 41 | +    - "default-pre.yml" | 
|  | 42 | + | 
|  | 43 | +- name: Install Caddy binaries | 
|  | 44 | +  ansible.builtin.package: | 
|  | 45 | +    name: "{{ caddy_package }}" | 
|  | 46 | +  loop: "{{ caddy_packages }}" | 
|  | 47 | +  loop_control: | 
|  | 48 | +    loop_var: caddy_package | 
|  | 49 | + | 
|  | 50 | +- name: Set up Caddyfile imports directory | 
|  | 51 | +  ansible.builtin.file: | 
|  | 52 | +    path: "/etc/caddy/Caddyfile.d" | 
|  | 53 | +    mode: "0755" | 
|  | 54 | +    state: directory | 
|  | 55 | + | 
|  | 56 | +- name: Set up Caddy WWW root directory | 
|  | 57 | +  ansible.builtin.file: | 
|  | 58 | +    path: "{{ caddy_www_root }}" | 
|  | 59 | +    mode: "0755" | 
|  | 60 | +    state: directory | 
|  | 61 | + | 
|  | 62 | +- name: Set up default index page for Caddy WWW root | 
|  | 63 | +  ansible.builtin.file: | 
|  | 64 | +    path: "{{ [caddy_www_root, 'index.html'] | path_join }}" | 
|  | 65 | +    mode: "0755" | 
|  | 66 | +    state: touch | 
|  | 67 | + | 
|  | 68 | +- name: Provision external CA certificates | 
|  | 69 | +  when: caddy_ca_pem is defined | 
|  | 70 | +  block: | 
|  | 71 | +    - name: Set up external PKI directory | 
|  | 72 | +      ansible.builtin.file: | 
|  | 73 | +        path: "{{ caddy_external_pki_dir }}" | 
|  | 74 | +        state: directory | 
|  | 75 | +        owner: caddy | 
|  | 76 | +        group: caddy | 
|  | 77 | +        mode: "0700" | 
|  | 78 | + | 
|  | 79 | +    - name: Install external CA certificates | 
|  | 80 | +      ansible.builtin.copy: | 
|  | 81 | +        src: "{{ __ca_file }}" | 
|  | 82 | +        dest: "{{ [caddy_external_pki_dir, __ca_file | basename] | path_join }}" | 
|  | 83 | +        owner: caddy | 
|  | 84 | +        group: caddy | 
|  | 85 | +        mode: "0600" | 
|  | 86 | +      loop: | 
|  | 87 | +        - "{{ caddy_ca_pem }}" | 
|  | 88 | +        - "{{ caddy_ca_key }}" | 
|  | 89 | +      loop_control: | 
|  | 90 | +        loop_var: __ca_file | 
|  | 91 | + | 
|  | 92 | +# - name: Set up Caddyfile ACME issuers | 
|  | 93 | +#   ansible.builtin.blockinfile: | 
|  | 94 | +#     backup: no | 
|  | 95 | +#     path: "/etc/caddy/Caddyfile" | 
|  | 96 | +#     insertbefore: BOF | 
|  | 97 | +#     # append_newline: yes <=2.16 | 
|  | 98 | +#     block: | | 
|  | 99 | +#       { | 
|  | 100 | +#         cert_issuer acme | 
|  | 101 | +#         cert_issuer acme { | 
|  | 102 | +#           dir https://acme.zerossl.com/v2/DV90 | 
|  | 103 | + | 
|  | 104 | +#         } | 
|  | 105 | +#       } | 
|  | 106 | + | 
|  | 107 | +# - name: Set up Caddy CA | 
|  | 108 | +#   when: caddy_self_signed | 
|  | 109 | +#   ansible.builtin.blockinfile: | 
|  | 110 | +#     backup: no | 
|  | 111 | +#     path: "/etc/caddy/Caddyfile" | 
|  | 112 | +#     insertbefore: BOF | 
|  | 113 | +#     # append_newline: yes <=2.16 | 
|  | 114 | +#     block: "{{ lookup('template', 'internal_ca.json.j2') }}" | 
|  | 115 | + | 
|  | 116 | +# - name: Set up Caddyfile imports directive | 
|  | 117 | +#   ansible.builtin.blockinfile: | 
|  | 118 | +#     backup: no | 
|  | 119 | +#     path: "/etc/caddy/Caddyfile" | 
|  | 120 | +#     insertafter: EOF | 
|  | 121 | +#     # prepend_newline: yes <=2.16 | 
|  | 122 | +#     block: | | 
|  | 123 | +#       import Caddyfile.d/*.caddyfile | 
|  | 124 | + | 
|  | 125 | +- name: Provision Caddy configuration | 
|  | 126 | +  ansible.builtin.template: | 
|  | 127 | +    src: Caddyfile.j2 | 
|  | 128 | +    dest: /etc/caddy/Caddyfile | 
|  | 129 | +    mode: "0755" | 
|  | 130 | + | 
|  | 131 | +- name: Enable and run the Caddy service | 
|  | 132 | +  ansible.builtin.service: | 
|  | 133 | +    name: "{{ caddy_service }}" | 
|  | 134 | +    enabled: true | 
|  | 135 | +    state: started | 
|  | 136 | + | 
|  | 137 | +- name: Retrieve the Caddy self-signed CA certificate | 
|  | 138 | +  when: caddy_self_signed and caddy_ca_pem is undefined | 
|  | 139 | +  ansible.builtin.fetch: | 
|  | 140 | +    src: /var/lib/caddy/.local/share/caddy/pki/authorities/local/root.crt | 
|  | 141 | +    dest: "{{ [playbook_dir, name_prefix + '-caddy-root.crt'] | path_join }}" | 
|  | 142 | +    flat: true | 
0 commit comments