-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaybook.yml
More file actions
53 lines (50 loc) · 1.73 KB
/
playbook.yml
File metadata and controls
53 lines (50 loc) · 1.73 KB
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
---
- name: Create a partition of 40GB for Docker and install Docker
hosts: docker_swarm_manager, docker_swarm_worker
become: true
tasks:
- name: Make sure Docker daemon starts automatically at system startup
service:
name: docker
state: started
enabled: true
roles:
- ansible-role-partition
- ansible-role-docker
- name: Securely expose the Docker Daemon REST APIs
hosts: docker_swarm_manager, docker_swarm_worker
roles:
- role: ansible-role-docker-remote-api
docker_remote_client_use_certs_as_default: true
docker_remote_server_force_deploy: true
docker_remote_client_become: true
docker_remote_certs_server_additional_subjects:
- "DNS:{{ ansible_hostname }}"
- "IP:{{ ip }}"
- name: Set up a Docker Swarm on VMs
hosts: docker_swarm_manager, docker_swarm_worker
become: true
roles:
- ansible-dockerswarm
vars:
docker_swarm_interface: "eth1"
- name: Create a test service "web1" from the local machine to the Docker Swarm
hosts: localhost
tasks:
- name: Check if the service "web1" already exists
shell: docker service ls -f name=web1 | grep '\sweb1\s' | awk '{ print $1 }'
environment:
DOCKER_HOST: "tcp://192.168.77.21:2376"
DOCKER_TLS_VERIFY: 1
register: service_exists
changed_when: false
- name: Create a nginx service "web1" on the Docker Swarm
command: docker service create --replicas 2 -p 80:80 --name web1 nginx
environment:
DOCKER_HOST: "tcp://192.168.77.21:2376"
DOCKER_TLS_VERIFY: 1
register: docker_service_deploy_result
when: service_exists.stdout | length == 0
- name: Show the result
debug:
var: docker_service_deploy_result