Commit 9829e6fe0c998225b04cd091c9cd78b6e2b4bf13

Authored by Ricardo Gonçalves
1 parent 3d04eefdca
Exists in master

changes

hosts
... ... @@ -18,8 +18,8 @@
18 18 # Ex 2: A collection of hosts belonging to the 'webservers' group
19 19  
20 20 [webservers]
21   -10.10.10.57:22 ansible_ssh_user=ubuntu ansible_python_interpreter={{path_to_python}}
22   -10.10.10.47:22 ansible_ssh_user=ubuntu ansible_python_interpreter={{path_to_python}}
  21 +{{webserver1}}:22 ansible_ssh_user=ubuntu ansible_python_interpreter={{path_to_python}}
  22 +{{webserver2}}:22 ansible_ssh_user=ubuntu ansible_python_interpreter={{path_to_python}}
23 23  
24 24 # If you have multiple hosts following a pattern you can specify
25 25 # them like this:
... ... @@ -29,7 +29,7 @@
29 29 # Ex 3: A collection of database servers in the 'dbservers' group
30 30  
31 31 [dbservers]
32   -10.10.10.74:22 ansible_ssh_user=ubuntu ansible_python_interpreter={{path_to_python}}
  32 +{{dbserver}}:22 ansible_ssh_user=ubuntu ansible_python_interpreter={{path_to_python}}
33 33  
34 34 # Here's another example of host ranges, this time there are no
35 35 # leading 0s:
... ... @@ -37,7 +37,7 @@
37 37 #db-[99:101]-node.example.com
38 38  
39 39 [proxyserver]
40   -10.10.10.33:30023 ansible_ssh_user=ubuntu ansible_python_interpreter={{path_to_python}}
  40 +{{proxyserver}}:30023 ansible_ssh_user=ubuntu ansible_python_interpreter={{path_to_python}}
41 41  
42 42 [jenkinserver]
43 43 193.136.46.156:30022 ansible_ssh_user=ubuntu
... ...
playbook.yml
... ... @@ -6,6 +6,8 @@
6 6 - proxyserver
7 7 vars_files:
8 8 - vars/vars.yaml
  9 + when:
  10 + - proxyflag
9 11  
10 12 - hosts: webservers
11 13 become: true
... ... @@ -14,6 +16,8 @@
14 16 - webserver
15 17 vars_files:
16 18 - vars/vars.yaml
  19 + when:
  20 + - webflag
17 21  
18 22 - hosts: dbservers
19 23 become: true
... ... @@ -21,4 +25,6 @@
21 25 - docker-git-pip
22 26 - dbserver
23 27 vars_files:
24   - - vars/vars.yaml
25 28 \ No newline at end of file
  29 + - vars/vars.yaml
  30 + when:
  31 + - dbflag
26 32 \ No newline at end of file
... ...
roles/dbserver/tasks/main.yml
... ... @@ -4,11 +4,15 @@
4 4 dest: "{{db_dir}}/"
5 5 clone: yes
6 6 force: yes
  7 + when:
  8 + - var
7 9  
8 10 - name: Building docker-compose file to {{db_dir}}
9 11 win_template:
10 12 src: docker-compose.yml
11 13 dest: "{{db_dir}}/"
  14 + when:
  15 + - var
12 16  
13 17 - name: Running containers with docker-compose
14 18 docker_service:
... ...
roles/docker-git-pip/tasks/main.yml
1 1 - name: Add Docker GPG key
2 2 apt_key: url=https://download.docker.com/linux/ubuntu/gpg
  3 + when:
  4 + - depend_flag
3 5  
4 6 - name: Add Docker APT repository
5 7 apt_repository:
6 8 repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ansible_distribution_release}} stable
  9 + when:
  10 + - depend_flag
7 11  
8 12 - name: Install list of packages
9 13 apt:
10 14 name: ['apt-transport-https','ca-certificates','curl','software-properties-common','docker-ce']
11 15 state: present
12 16 update_cache: yes
  17 + when:
  18 + - depend_flag
13 19  
14 20 - name: Installing Git and pip
15 21 apt:
16 22 update_cache: yes
17   - name: ['git', 'python-pip']
  23 + name: ['git', 'python-pip', 'python3-pip']
18 24 state: present
  25 + when:
  26 + - depend_flag
19 27  
20 28 - name: Installing Docker dependencies
21 29 pip:
22   - name: "{{item}}"
  30 + name: ['docker-compose']
23 31 state: present
24   - with_items:
25   - - docker-compose
  32 + executable: /usr/bin/pip3
  33 + when:
  34 + - depend_flag
... ...
roles/proxyserver/tasks/main.yml
... ... @@ -4,17 +4,22 @@
4 4 dest: "{{proxy_dir}}/"
5 5 clone: yes
6 6 force: yes
  7 + when:
  8 + - var
7 9  
8 10 - name: Building haproxy config to {{proxy_dir}}
9 11 win_template:
10 12 src: haproxy.cfg
11 13 dest: "{{proxy_dir}}/"
12   -
  14 + when:
  15 + - var
13 16  
14 17 - name: Building docker-compose file to {{proxy_dir}}
15 18 win_template:
16 19 src: docker-compose.yml
17 20 dest: "{{proxy_dir}}/"
  21 + when:
  22 + - var
18 23  
19 24 - name: Running containers with docker-compose
20 25 docker_service:
... ...
roles/webserver/tasks/main.yml
... ... @@ -4,21 +4,29 @@
4 4 dest: "{{webs_dir}}/"
5 5 clone: yes
6 6 force: yes
  7 + when:
  8 + - var
7 9  
8 10 - name: Building nginx config to {{webs_dir}}nginx_cont/
9 11 win_template:
10 12 src: nginx.conf
11 13 dest: "{{webs_dir}}nginx_cont/"
  14 + when:
  15 + - var
12 16  
13 17 - name: Building app settings to {{webs_dir}}appdjango_cont/
14 18 win_template:
15 19 src: settings.py
16 20 dest: "{{webs_dir}}appdjango_cont/"
  21 + when:
  22 + - var
17 23  
18   -- name: Building docker-compose file to {{webs_dir}}/
  24 +- name: Building docker-compose file to {{webs_dir}}
19 25 win_template:
20 26 src: docker-compose.yml
21 27 dest: "{{webs_dir}}/"
  28 + when:
  29 + - var
22 30  
23 31 - name: Running containers with docker-compose
24 32 docker_service:
... ...
vars/vars.yaml
... ... @@ -17,12 +17,19 @@ path_to_python: /usr/bin/python2.7
17 17 proxy_port: 8002
18 18 webser_port: 8090
19 19 app_port: 8000
20   -browser_port: 30098
  20 +browser_port: 80
21 21  
22 22 #máquinas que correm a app
  23 +proxyserver: 10.10.10.33
23 24 webserver1: 10.10.10.57
24 25 webserver2: 10.10.10.47
25 26 db_server: 10.10.10.74
26 27  
27 28 #variavel que permite correr os containers
28   -var: true
29 29 \ No newline at end of file
  30 +var: true
  31 +
  32 +#variaveis que controlar o deploy para as respetivas máquinas
  33 +dbflag: true
  34 +webflag: true
  35 +proxyflag: true
  36 +depend_flag: true
30 37 \ No newline at end of file
... ...