<commit_before>---
- hosts: docker
  become: yes
  tasks:
    - name: Stopping app {{ container_name }}
      docker:
          name: "{{ container_name }}"
          image: "{{ docker_repo }}/{{ image_name }}"
          state: absent                    # the container is removed, otherwise starting with the same name fails later on.
      register: stopappoutput
    - debug: var=stopappoutput.msg

# Bring the database up to the newest version
- hosts: buildserver                       # flyway is located on the build-server, the buildserver connects to the db machines
  tasks:
    - name: "Updating the database"
      command: flyway -user={{ db_user }} -password={{ db_password }} -url="jdbc:mysql://{{ item }}:{{ db_port }}" -schemas="{{ db_name }}" -locations=filesystem:{{ flyway_migration_location }} migrate
      chdir: "{{ app_deployment_dir }}"
      register: flywayoutput
      with_inventory_hostnames: db   # loop this task over all databases
    - debug: var=flywayoutput.results[0].stdout_lines   # when deploying, we would want to see output of the database migration

- hosts: docker
  become: yes
  tasks:
    - name: Starting the docker image {{ docker_repo }}/{{ image_name }}:{{ image_version }} with name {{ container_name }}
      docker:
          name: "{{ container_name }}"
          image: "{{ docker_repo }}/{{ image_name }}:{{ image_version }}"
          ports: "{{ public_application_port }}:{{ port_in_container }}"
          restart_policy: on-failure
          state: started
          env:
              DB_CONNECTION_STRING: mysql://{{ db_user }}:{{ db_password }}@{{ item }}:{{ db_port }}/{{ db_name }}
      register: startappoutput
      with_inventory_hostnames: db   # this works because there is only one item under db that will be mapped to item
    - debug: var=startappoutput.results[0].msg<commit_msg>args syntax for command module<commit_after>---
- hosts: docker
  become: yes
  tasks:
    - name: Stopping app {{ container_name }}
      docker:
          name: "{{ container_name }}"
          image: "{{ docker_repo }}/{{ image_name }}"
          state: absent                    # the container is removed, otherwise starting with the same name fails later on.
      register: stopappoutput
    - debug: var=stopappoutput.msg

# Bring the database up to the newest version
- hosts: buildserver                       # flyway is located on the build-server, the buildserver connects to the db machines
  tasks:
    - name: "Updating the database"
      command: flyway -user={{ db_user }} -password={{ <PASSWORD> }} -url="jdbc:mysql://{{ item }}:{{ db_port }}" -schemas="{{ db_name }}" -locations=filesystem:{{ flyway_migration_location }} migrate
      args:
        chdir: "{{ app_deployment_dir }}"
      register: flywayoutput
      with_inventory_hostnames: db   # loop this task over all databases
    - debug: var=flywayoutput.results[0].stdout_lines   # when deploying, we would want to see output of the database migration

- hosts: docker
  become: yes
  tasks:
    - name: Starting the docker image {{ docker_repo }}/{{ image_name }}:{{ image_version }} with name {{ container_name }}
      docker:
          name: "{{ container_name }}"
          image: "{{ docker_repo }}/{{ image_name }}:{{ image_version }}"
          ports: "{{ public_application_port }}:{{ port_in_container }}"
          restart_policy: on-failure
          state: started
          env:
              DB_CONNECTION_STRING: mysql://{{ db_user }}:{{ db_password }}@{{ item }}:{{ db_port }}/{{ db_name }}
      register: startappoutput
      with_inventory_hostnames: db   # this works because there is only one item under db that will be mapped to item
    - debug: var=startappoutput.results[0].msg
{'fraction_non_alphanumeric': 0.11998931052912881, 'fraction_numerical': 0.0010689470871191875, 'mean_word_length': 2.7961460446247464, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3395153', 'n_tokens_mistral': 1066, 'n_tokens_neox': 1041, 'n_words': 330}