---
- name: update inception
  hosts: all
  vars:
    app_dir: "{{ app_dir | default('/root/code/inception') }}"
  tasks:
  # - name: Change to the app directory and update the repository
  #   git:
  #     repo: 'https://gt.eron.co/eron/inception.git'  # Replace with your repository URL
  #     dest: /root/code/inception
  #     version: master
  #   register: git_result
  - name: Go to the application directory
    command: chdir={{ app_dir }} git pull origin master
    register: git_result

  - name: Build docker image if there were changes
    docker_image:
      source: build
      build:
        path: "{{ app_dir }}"
      name: inception
      tag: "{{semaphore_vars.task_details.target_version}}"
    when: git_result.changed