---
- name: AEM Author CloudFormation Stack
  hosts: all
  gather_facts: no
  connection: local

  tasks:

    - name: Create random credentials for system users
      system_users_credentials:
      register: credentials
      tags:
      - create

    - name: Ensure data bucket exists
      s3_bucket:
        name: "{{ s3.data_bucket_name }}"
        state: present
      tags:
      - create

    - name: Upload stack init script
      s3:
        bucket: "{{ s3.data_bucket_name }}"
        object: "{{ stack_prefix }}/stack-init.sh"
        src: ../../../scripts/stack-init.sh
        mode: put
      tags:
      - create

    - name: Upload stack provisioner
      s3:
        bucket: "{{ s3.data_bucket_name }}"
        object: "{{ stack_prefix }}/aem-aws-stack-provisioner.tar.gz"
        src: ../../../stage/aem-aws-stack-provisioner.tar.gz
        mode: put
      tags:
      - create

    - name: Delete stack data
      s3:
        bucket: "{{ s3.data_bucket_name }}"
        object: "{{ stack_prefix }}"
        mode: delobj
      tags:
      - delete

---
- name: AEM Author CloudFormation Stack
  hosts: all
  gather_facts: no
  connection: local

  tasks:

    - name: Generate random credentials for system users
      system_users_credentials:
      register: credentials
      tags:
      - create

    - name: Ensure stage directory exists
      file:
        path: ../../../stage
        state: directory
        mode: 0755
      tags:
      - create

    - name: Create temporary file containing generated credentials
      copy:
        content: "{{ credentials.meta }}"
        dest: ../../../stage/system_users_credentials.json
      tags:
      - create

    - name: Ensure data bucket exists
      s3_bucket:
        name: "{{ s3.data_bucket_name }}"
        state: present
      tags:
      - create

    - name: Upload stack init script
      s3:
        bucket: "{{ s3.data_bucket_name }}"
        object: "{{ stack_prefix }}/stack-init.sh"
        src: ../../../scripts/stack-init.sh
        mode: put
      tags:
      - create

    - name: Upload stack provisioner
      s3:
        bucket: "{{ s3.data_bucket_name }}"
        object: "{{ stack_prefix }}/aem-aws-stack-provisioner.tar.gz"
        src: ../../../stage/aem-aws-stack-provisioner.tar.gz
        mode: put
      tags:
      - create

    - name: Upload system user credentials
      s3:
        bucket: "{{ s3.data_bucket_name }}"
        object: "{{ stack_prefix }}/system-users-credentials.json"
        src: ../../../stage/system-users-credentials.json
        mode: put
        encrypt: yes
      tags:
      - create

    - name: Delete stack data
      s3:
        bucket: "{{ s3.data_bucket_name }}"
        object: "{{ stack_prefix }}"
        mode: delobj
      tags:
      - delete

Add system user credentials upload to S3.
Add system user credentials upload to S3.
