homeserver/roles/mgrote.docker-compose-deploy/tasks/dockercompose-up.yml
mg dae1ff8a54 docker-compose: login daten (#200)
Co-authored-by: Michael Grote <michael.grote@posteo.de>
Reviewed-on: mg/ansible#200
Co-authored-by: mg <mg@noreply.git.mgrote.net>
Co-committed-by: mg <mg@noreply.git.mgrote.net>
2021-09-02 21:22:18 +02:00

50 lines
1.8 KiB
YAML

---
- 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
- name: check if repo exists - "{{ item.name }}" (wenn der Task >30s dauert sind die Login-Daten falsch)
stat:
path: "{{ project_dir }}"
register: repo_exists
- name: stash changes - "{{ item.name }}"
ansible.builtin.shell: git stash
args:
chdir: "{{ project_dir }}"
changed_when: false
when: repo_exists.stat.exists == true
- name: clone repository - "{{ item.name }}"
ansible.builtin.git:
repo: "https://{{ login | default () }}{{ item.repository_url }}"
dest: "{{ project_dir }}"
version: "{{ item.git_branch | default ('master') }}"
register: repo
- 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
- name: unset username and passwort - "{{ item.name }}"
set_fact:
login: ""