---
- name: AEM App Stack Private Cert Creation
  hosts: all
  gather_facts: no
  connection: local

  tasks:
    - name: Create AEM App Stack Private SSL Cert Used in ELBs
      cloudformation:
        stack_name: "{{ stack_prefix }}-{{ cert_private.stack_name }}"
        region: "{{ aws.region }}"
        state: present
        template: "../../../cloudformation/apps/cert-private.yaml"
        template_parameters:
          ComputeStackPrefixParameter: "{{ stack_prefix }}"
          ApexDomainParameter: "{{ dns.apex_domain_name  | regex_replace('(.*)\\.', '\\1') }}"
          StackSubdomainParameter: "{{ stack_prefix }}.{{ dns.stack_sub_domain }}"
      tags:
      - create

    - name: Check if a Stack Exists
      command: >
        aws cloudformation describe-stacks --stack-name "{{ stack_prefix }}-{{ cert_private.stack_name}}"
             --query 'Stacks[].StackName' --region "{{ aws.region }}"
      ignore_errors: True
      register: stack_query
      tags:
        - delete

    - name: Report Stack Problem
      debug:
        msg: Stack "{{ stack_prefix }}-{{ cert_private.stack_name }}" does not exist or some other errors occured
      when:
        "stack_query.rc != 0"
      tags:
        - delete

    - name: Delete AEM App Stack Private SSL Cert
      cloudformation:
        stack_name: "{{ stack_prefix }}-{{ cert_private.stack_name }}"
        region: "{{ aws.region }}"
        state: absent
      when:
        "stack_query.rc == 0"
      tags:
      - delete

---
- name: AEM App Stack Private Cert Creation
  hosts: all
  gather_facts: no
  connection: local

  tasks:
    - name: Create AEM App Stack Private SSL Cert Used in ELBs
      cloudformation:
        stack_name: "{{ stack_prefix }}-{{ cert_private.stack_name }}"
        region: "{{ aws.region }}"
        state: present
        template: "../../../cloudformation/apps/cert-private.yaml"
        template_parameters:
          ComputeStackPrefixParameter: "{{ stack_prefix }}"
          ApexDomainParameter: "{{ dns.apex_domain_name  | regex_replace('(.*)\\.', '\\1') }}"
          StackSubdomainParameter: "{{ stack_prefix }}.{{ dns.stack_sub_domain }}"
          BlueGreenSubdomainParameter: "{{ dns.blue_green_sub_domain }}.{{ dns.stack_sub_domain }}"
      tags:
      - create

    - name: Check if a Stack Exists
      command: >
        aws cloudformation describe-stacks --stack-name "{{ stack_prefix }}-{{ cert_private.stack_name}}"
             --query 'Stacks[].StackName' --region "{{ aws.region }}"
      ignore_errors: True
      register: stack_query
      tags:
        - delete

    - name: Report Stack Problem
      debug:
        msg: Stack "{{ stack_prefix }}-{{ cert_private.stack_name }}" does not exist or some other errors occured
      when:
        "stack_query.rc != 0"
      tags:
        - delete

    - name: Delete AEM App Stack Private SSL Cert
      cloudformation:
        stack_name: "{{ stack_prefix }}-{{ cert_private.stack_name }}"
        region: "{{ aws.region }}"
        state: absent
      when:
        "stack_query.rc == 0"
      tags:
      - delete

Add blue-green DNS name parameter to private certificate stack.
Add blue-green DNS name parameter to private certificate stack.
