- name: Deploy Application hosts: api remote_user: root pre_tasks: - name: "Assert project_name is provided and not empty" assert: that: - project_name is not undefined and project_name != "" tasks: # debug section - debug: var=inventory_hostname - name: check resolv.conf file exists stat: path: /etc/resolv.conf register: resolv_conf - name: print a debug message when resolv.config file does not exists debug: msg: "The resolv.conf path doesn't exist." when: resolv_conf.stat.exists == False - name: "read /etc/resolv.conf" command: /bin/cat /etc/resolv.conf register: resolv_content - debug: msg="{{ resolv_content.stdout_lines | quote }}" ## Login - name: Login to registry docker_login: registry_url: "{{ registry_url }}" username: "{{ registry_username }}" password: "{{ registry_password }}" reauthorize: true # Deploy image - name: Create config directory file: path: "{{ config_dir }}" # /etc/app-x-y state: directory recurse: yes - name: Create .env file file: state: touch path: "{{ config_dir }}/.env" mode: '0600' - name: Execute docker-compose shell: cd "{{ config_dir }}" && docker-compose down ignore_errors: true - name: "Upload docker-compose template" # fills the tempalte with variables from ansile template: src: "templates/docker-compose-api.yml" dest: "{{ config_dir }}/docker-compose.yml" - name: Execute docker-compose shell: cd "{{ config_dir }}" && docker-compose up -d - name: Create log file file: path: "/var/log/{{ project_name }}" state: directory recurse: yes