# Expected vars
# - name...
# - SSLCertificateChainFile:
# - cert:
# - key:

- name: Copy over SSLCertificateChainFile if defined
  copy: >
    src={{private}}/files/httpd/{{SSLCertificateChainFile}}
    dest=/etc/pki/tls/certs/{{SSLCertificateChainFile}}
    owner=root
    group=root
    mode=0644
  when: SSLCertificateChainFile is defined
  notify:
  - restart httpd
  tags:
  - httpd
  - httpd/certificate

- name: Copy {{name}}.cert
  copy: >
    src={{item}}
    dest=/etc/pki/tls/certs/{{item | basename}}
    owner=root
    group=root
    mode=0644
  with_first_found:
  - "{{private}}/files/httpd/{{cert}}.cert"
  - "{{private}}/files/httpd/{{name}}.cert"
  notify:
  - restart httpd
  tags:
  - httpd
  - httpd/certificate

- name: Copy {{name}}.key
  copy: >
    src={{item}}
    dest=/etc/pki/tls/private/{{item | basename}}
    owner=root
    group=root
    mode=0600
  with_first_found:
  - "{{private}}/files/httpd/{{key}}.key"
  - "{{private}}/files/httpd/{{name}}.key"
  notify:
  - restart httpd
  tags:
  - httpd
  - httpd/certificate
