-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaybook.yaml
92 lines (79 loc) · 2.31 KB
/
playbook.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
---
- hosts: all
# - hosts: localhost
# connection: local
become: true
vars_files:
- config.yaml
tasks:
- name: Update apt cache
apt:
update_cache: yes
- name: Install prerequisite packages
apt:
name:
- apt-transport-https
- ca-certificates
- curl
- gnupg
- lsb-release
state: present
- name: Add Docker's GPG key
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
- name: Add Docker repository
apt_repository:
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu jammy stable
state: present
- name: Install Docker and Docker Compose
apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-compose
state: present
# Simulating deployment
- name: Create Nginx directories
file:
path: "/opt/nginx{{ item }}"
state: directory
mode: '0755'
with_sequence: start=1 end={{ containers.nginx.replicaCount }}
- name: Create Nginx index.html files
copy:
content: "Response from Server {{ item }}"
dest: "/opt/nginx{{ item }}/index.html"
mode: '0644'
with_sequence: start=1 end={{ containers.nginx.replicaCount }}
## Starting Deploy process
- name: Create directories for Docker Compose and configurations
file:
path: "{{ item }}"
state: directory
mode: '0755'
with_items:
- /opt/app
- /opt/haproxy
- name: Generate docker-compose.yml
template:
src: templates/docker-compose.yml.j2
dest: /opt/app/docker-compose.yml
mode: '0644'
- name: Generate HAProxy configuration
template:
src: templates/haproxy.cfg.j2
dest: /opt/haproxy/haproxy.cfg
mode: '0644'
- name: Start Docker Compose services
shell: |
docker-compose -f /opt/app/docker-compose.yml up -d --force-recreate
args:
chdir: /opt/app
# It can be used as a mode if more control is needed but this will require more packages to be installed
# - name: Start Docker Compose services
# docker_compose:
# project_src: /opt/app
# state: present
# restarted: true