-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvm-playbook.yml
98 lines (79 loc) · 2.56 KB
/
vm-playbook.yml
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
91
92
93
94
95
96
97
98
- hosts: es-vm
vars:
dc_version: '1.23.1'
repo_dest_path: ./stroam
vars_prompt:
- name: "gituser"
prompt: "Enter git username"
private: no
- name: "gitpassword"
prompt: "Enter git password"
private: yes
tasks:
- name: Check if Docker is installed
command: dpkg-query -l 'docker-ce'
ignore_errors: yes
register: docker_installed
- block:
- name: Install Docker
block:
- name: Add Docker GPG key
apt_key: url=https://download.docker.com/linux/ubuntu/gpg
- name: Add Docker APT repository
apt_repository:
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ansible_distribution_release}} stable
- name: Install list of packages
apt:
name: "{{ item }}"
state: present
update_cache: yes
with_items:
- apt-transport-https
- ca-certificates
- curl
- software-properties-common
- docker-ce
become: yes
when: docker_installed is failed
- debug:
var: docker_installed.stderr
- name: Check if docker is running
command: systemctl status docker
ignore_errors: yes
register: docker_running
- debug:
var: docker_running.stdout
- name: Check if Docker Compose is installed
command: docker-compose --version
ignore_errors: yes
register: docker_compose_installed
- block:
- name: Install Docker Compose ({{ dc_version }})
shell: curl -L https://github.com/docker/compose/releases/download/{{dc_version}}/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
- name: Setting permission to execute Docker Compose
file:
path: /usr/local/bin/docker-compose
mode: a+x
become: yes
when: docker_compose_installed is failed
- block:
- name: Start Docker if it's not started yet
command: dockerd
become: yes
when: docker_running.stderr != ""
- name: Clone git code, and put it on the folder
git:
repo: "https://{{ gituser | urlencode }}:{{ gitpassword | urlencode }}@code.ua.pt/git/es1819-stroam"
dest: ./stroam
- block:
- name: Build docker-compose file
command: chdir=./stroam docker-compose build
become: yes
- name: Run all containers in docker-compose file detached
command: chdir=./stroam docker-compose up -d
become: yes
- debug:
var: docker_running
- debug:
var: docker_compose_installed
when: (docker_running) and (docker_compose_installed)