---
  # "Regenerate certificates based on the correct hostname."
  
  - name: "Check if the the gen certs flag file exists."
    find:
       paths: "{{ fwd_install_root }}{{ fwd_app_name }}/deploy/server/"
       patterns: "gen_certs_completed.flag"
    register: flag_file
    changed_when: false
  
  - name: "Generate new private key, self signed certificates and store them in both the directory and in a key store."
    shell: java -classpath ../../p2j/build/lib/p2j.jar com.goldencode.p2j.security.SSLCertGenUtil -dir directory.xml -rsa 2048 -exp 65537 --reuse-passwords yes --reuse-ca yes --private-key-password L\>8sp5Oy8ghSc*K969\(CJTL^jEKx9U0R --export-account-keys yes --use-common-account-store no --export-server-keys yes --use-common-server-store no --export-server-certs yes --include-ca yes --server-certs-store srv-certs.store --export-ca-key yes --root-private-keys-store root-ca-pk.store
    args:
       chdir: "{{ fwd_install_root }}/{{ fwd_app_name }}/deploy/server/"
    register: gen_result_self_signed
    when: gen_certs|bool and gen_certs_self_signed|bool and flag_file.matched|int == 0

  - name: "Generate the certificate import file so browsers can trust the recently generated certs."
    shell: echo 169ghwa^G0f%O9p\<\`feODy1q7NTFWI8j | keytool -exportcert -alias hotel-root -keystore srv-certs.store -file hotel-root.der
    args:
       chdir: "{{ fwd_install_root }}/{{ fwd_app_name }}/deploy/server/"
    when: gen_certs|bool and gen_certs_self_signed|bool and flag_file.matched|int == 0 and gen_result_self_signed.rc == 0
    notify: "create flag file"
  
  - name: "Generate new private key, Let's Encrypt certificates and store them in both the directory and in a key store."
    shell: java -classpath ../../p2j/build/lib/p2j.jar com.goldencode.p2j.security.SSLCertGenUtil -dir directory.xml --rsa-key-size 2048 --rsa-public-exponent 65337 --reuse-passwords no --private-key-password L\>8sp5Oy8ghSc*K969\(CJTL^jEKx9U0R --export-account-keys yes --use-common-account-store no --export-server-keys yes --use-common-server-store no --export-server-certs yes --include-ca yes --server-certs-store srv-certs.store --export-ca-key yes --root-private-keys-store root-ca-pk.store -domains "test8.acme.com    test7.acme.com" --lets-encrypt-client-host "{{ fwd_srv_hostname }}" --lets-encrypt-client-port 9999 --lets-encrypt-server "acme://letsencrypt.org/staging" -S O="{{ gen_certs_subject_O }}" -S OU="{{ gen_certs_subject_OU }}" -S C="{{ gen_certs_subject_C }}" -S L="{{ gen_certs_subject_L }}" -S S="{{ gen_certs_subject_S }}" -acme REQUEST
    args:
       chdir: "{{ fwd_install_root }}/{{ fwd_app_name }}/deploy/server/"
    register: gen_result_lets_encrypt
    when: gen_certs|bool and gen_certs_lets_encrypt|bool and flag_file.matched|int == 0
    notify: "create flag file"

