2021-07-20 10:14:07 +02:00
|
|
|
---
|
|
|
|
- name: set username and passwort - "{{ item.name }}"
|
|
|
|
set_fact:
|
|
|
|
login: "{{ item.repository_user }}:{{ item.repository_user_password }}@"
|
|
|
|
when:
|
|
|
|
- item.repository_user is defined
|
|
|
|
- item.repository_user_password is defined
|
|
|
|
|
|
|
|
- name: set dir - "{{ item.name }}"
|
|
|
|
set_fact:
|
|
|
|
project_dir: "{{ docker_compose_base_dir }}/{{ item.dir_name | default (item.name) }}"
|
|
|
|
when:
|
|
|
|
- docker_compose_base_dir is defined
|
|
|
|
- docker_compose_projects is defined
|
|
|
|
|
2021-09-02 21:22:18 +02:00
|
|
|
- name: check if repo exists - "{{ item.name }}" (wenn der Task >30s dauert sind die Login-Daten falsch)
|
2021-07-20 10:14:07 +02:00
|
|
|
stat:
|
|
|
|
path: "{{ project_dir }}"
|
|
|
|
register: repo_exists
|
|
|
|
|
2022-04-14 13:23:39 +02:00
|
|
|
- name: set safe directory
|
|
|
|
become: true
|
|
|
|
ansible.builtin.shell:
|
|
|
|
cmd: git config --global --add safe.directory "{{ project_dir }}"
|
|
|
|
changed_when: false
|
|
|
|
|
2021-07-20 10:14:07 +02:00
|
|
|
- name: stash changes - "{{ item.name }}"
|
|
|
|
ansible.builtin.shell: git stash
|
|
|
|
args:
|
|
|
|
chdir: "{{ project_dir }}"
|
|
|
|
changed_when: false
|
|
|
|
when: repo_exists.stat.exists == true
|
|
|
|
|
2021-07-21 10:10:42 +02:00
|
|
|
- name: clone repository - "{{ item.name }}"
|
2021-07-20 10:14:07 +02:00
|
|
|
ansible.builtin.git:
|
|
|
|
repo: "https://{{ login | default () }}{{ item.repository_url }}"
|
|
|
|
dest: "{{ project_dir }}"
|
2021-07-20 10:27:33 +02:00
|
|
|
version: "{{ item.git_branch | default ('master') }}"
|
2021-07-20 10:14:07 +02:00
|
|
|
register: repo
|
|
|
|
|
2021-10-22 15:58:27 +02:00
|
|
|
- name: set owner recursive for repo
|
|
|
|
file:
|
|
|
|
path: "{{ project_dir }}"
|
|
|
|
owner: "{{ item.os_username }}"
|
|
|
|
group: "{{ item.os_username }}"
|
|
|
|
recurse: yes
|
|
|
|
when: repo is changed
|
|
|
|
|
2021-07-20 10:14:07 +02:00
|
|
|
- name: create networks - "{{ item.name }}"
|
|
|
|
ansible.builtin.shell: "docker network create {{ item.network_name }}" # erstelle network
|
|
|
|
when: "item.network_name is defined" # wenn network_name definiert ist
|
|
|
|
register: network_result # speichere ergebnis in var
|
|
|
|
changed_when: "network_result.rc == 0" # markiere tasks als changed when exit-code == 0
|
|
|
|
ignore_errors: yes # ignoriere fehler
|
|
|
|
|
|
|
|
- name: (re)start container - "{{ item.name }}"
|
|
|
|
ansible.builtin.shell: docker-compose down && docker-compose up -d
|
|
|
|
args:
|
|
|
|
chdir: "{{ project_dir }}"
|
|
|
|
when: repo.changed
|
2021-09-02 21:22:18 +02:00
|
|
|
|
|
|
|
- name: unset username and passwort - "{{ item.name }}"
|
|
|
|
set_fact:
|
|
|
|
login: ""
|