- name: deploy Airflow containers locally
  hosts: localhost
  vars:
    command: scheduler

  tasks:
    - name: launch Airflow containers
      shell: "{{ item }}"
      with_items:
        - docker stop $(docker ps -a -q) || true
        - docker rm $(docker ps -a -q) || true
        - docker volume rm $(docker volume ls -qf dangling=true) || true
        - docker-compose -f ansible/files/docker-compose.yml up -d
      environment:
        AWS_REGION: "{{ region }}"
        EMR_KEY_NAME: "{{ emr_key_name }}"
        EMR_RELEASE_LABEL: "{{ emr_release_label }}"
        EMR_FLOW_ROLE: "{{ emr_flow_role }}"
        EMR_SERVICE_ROLE: "{{ emr_service_role }}"
        EMR_INSTANCE_TYPE: "{{ emr_instance_type }}"
        SPARK_BUCKET: "{{ spark_bucket }}"
        AWS_ACCESS_KEY_ID: "{{ lookup('env', 'AWS_ACCESS_KEY_ID') }}"
        AWS_SECRET_ACCESS_KEY: "{{ lookup('env', 'AWS_SECRET_ACCESS_KEY') }}"
        DB_URI: "{{ db_uri }}"
        DB_USER: "{{ db_user }}"
        DB_PASSWORD: "{{ db_password }}"
        AIRFLOW_BUCKET: "{{ airflow_bucket }}"
        AIRFLOW_ENABLE_AUTH: False
        COMMAND: "{{ command }}"

- name: deploy Airflow containers locally
  hosts: localhost
  vars:
    command: scheduler
    compose_conf: ansible/files/docker-compose.yml

  tasks:
    - name: launch Airflow containers
      shell: "{{ item }}"
      with_items:
        - docker-compose -f {{ compose_conf }} down -v --remove-orphans
        - docker-compose -f {{ compose_conf }} up -d
      environment:
        AWS_REGION: "{{ region }}"
        EMR_KEY_NAME: "{{ emr_key_name }}"
        EMR_RELEASE_LABEL: "{{ emr_release_label }}"
        EMR_FLOW_ROLE: "{{ emr_flow_role }}"
        EMR_SERVICE_ROLE: "{{ emr_service_role }}"
        EMR_INSTANCE_TYPE: "{{ emr_instance_type }}"
        SPARK_BUCKET: "{{ spark_bucket }}"
        AWS_ACCESS_KEY_ID: "{{ lookup('env', 'AWS_ACCESS_KEY_ID') }}"
        AWS_SECRET_ACCESS_KEY: "{{ lookup('env', 'AWS_SECRET_ACCESS_KEY') }}"
        DB_URI: "{{ db_uri }}"
        DB_USER: "{{ db_user }}"
        DB_PASSWORD: "{{ db_password }}"
        AIRFLOW_BUCKET: "{{ airflow_bucket }}"
        AIRFLOW_ENABLE_AUTH: False
        COMMAND: "{{ command }}"

Use docker-compose to stop running containers.
Use docker-compose to stop running containers.
