72 lines
2.1 KiB
YAML
72 lines
2.1 KiB
YAML
---
|
|
- name: Deploy and start Movie-DB Application
|
|
hosts: all
|
|
become: False
|
|
gather_facts: True
|
|
|
|
vars:
|
|
project_name: movie-db
|
|
install_dir: "/opt/{{ project_name }}"
|
|
|
|
|
|
tasks:
|
|
- name: Create installation directory
|
|
ansible.builtin.file:
|
|
path: "{{ install_dir }}"
|
|
state: directory
|
|
mode: '0755'
|
|
|
|
- name: Copy project files
|
|
ansible.builtin.copy:
|
|
src: "{{ item }}"
|
|
dest: "{{ install_dir }}/"
|
|
owner: root
|
|
group: root
|
|
mode: '0644'
|
|
with_items:
|
|
- cert.pem
|
|
- docker-compose.yml
|
|
- Dockerfile
|
|
- genre_list
|
|
- imdb_suche.py
|
|
- key.pem
|
|
- main.py
|
|
- moviedb_func.py
|
|
- regie_name.csv
|
|
- requirements.txt
|
|
|
|
- name: Copy templates directory
|
|
ansible.builtin.copy:
|
|
src: templates/
|
|
dest: "{{ install_dir }}/templates/"
|
|
owner: root
|
|
group: root
|
|
|
|
- name: Start application with Docker Compose
|
|
community.docker.docker_compose_v2:
|
|
project_src: "{{ install_dir }}"
|
|
project_name: "{{ project_name }}"
|
|
recreate: always
|
|
register: compose_output
|
|
|
|
- name: Get container info
|
|
community.docker.docker_host_info:
|
|
containers: true
|
|
containers_all: true
|
|
register: host_info
|
|
until: (host_info.ansible_facts.docker_containers | selectattr('Labels.com.docker.compose.project', 'equalto', project_name) | list | length) >= 2
|
|
retries: 10
|
|
delay: 5
|
|
|
|
- name: Debug container_info
|
|
ansible.builtin.debug:
|
|
var: host_info.ansible_facts.docker_containers
|
|
|
|
- name: Verify that web and db services are running
|
|
ansible.builtin.assert:
|
|
that:
|
|
- (host_info.ansible_facts.docker_containers | selectattr('Labels.com.docker.compose.project', 'equalto', project_name) | selectattr('Names', 'match', '.*-web-.*') | first).State.Running
|
|
- (host_info.ansible_facts.docker_containers | selectattr('Labels.com.docker.compose.project', 'equalto', project_name) | selectattr('Names', 'match', '.*-db-.*') | first).State.Running
|
|
|
|
|