homeserver/roles/mgrote.docker-compose-deploy/tasks/dockercompose-up.yml
mg 40dc9e079d lazydocker (#168)
task name

lazydocker container

Co-authored-by: Michael Grote <michael.grote@posteo.de>
Reviewed-on: mg/ansible#168
Co-Authored-By: mg <mg@noreply.git.mgrote.net>
Co-Committed-By: mg <mg@noreply.git.mgrote.net>
2021-07-21 10:10:42 +02:00

46 lines
1.6 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 }}"
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