-
Notifications
You must be signed in to change notification settings - Fork 1
/
CentOS7x_Install-Docker-for-Rancher-playbook.yml
247 lines (199 loc) · 7.55 KB
/
CentOS7x_Install-Docker-for-Rancher-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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
---
################################################################################
# description: Installs Docker for a Rancher specific configuration on CentOS7x
# usage: ansible-playbook CentOS7x_Install-Docker-for-Rancher-playbook.yml --extra-vars 'HostOrGroup=YourServerOrGroupNameGoesHere'
# author: Ernest G. Wilson II <ErnestGWilsonII@gmail.com> (https://github.com/ernestgwilsonii)
# license: MIT
################################################################################
# Ansible Playbook options
# REF: http://docs.ansible.com/ansible/playbooks.html
#####################################################
- name: Install Docker for a Rancher specific configuration on CentOS7x
hosts: "{{ HostOrGroup|default ('FATAL ERROR --> HostOrGroup NOT SET! You must specify either a Host or a Group name!') }}"
serial: "100%"
gather_facts: False
tasks:
# Execute command(s)
# REF: http://docs.ansible.com/ansible/command_module.html
##########################################################
- name: Enable IPv4 Forwarding
command: /usr/sbin/sysctl -w net.ipv4.ip_forward=1
# Install or configure repository used on the OS by yum
# REF: https://docs.ansible.com/ansible/yum_repository_module.html
##################################################################
# /etc/yum.repos.d/docker.repo
- name: Install repository dockerrepo
yum_repository:
name: dockerrepo
description: Docker Repository
file: docker
baseurl: https://yum.dockerproject.org/repo/main/centos/7
enabled: yes
gpgcheck: yes
gpgkey: https://yum.dockerproject.org/gpg
# Install yum packages
# REF: http://docs.ansible.com/ansible/yum_module.html
######################################################
- name: Install bind-utils
yum:
name: bind-utils
state: latest
- name: Install bridge-utils
yum:
name: bridge-utils
state: latest
# brctl show
# Download and install a specific supported Docker version for Rancher + Kubernetes (allows Kubernetes and Kubernetes dashboard to work)
# REF: http://docs.rancher.com/rancher/v1.5/en/hosts/#supported-docker-versions
# - name: Install Docker 1.12.x
# command: /usr/bin/curl https://releases.rancher.com/install-docker/1.12.sh | /usr/bin/sh
# https://github.com/docker/docker/releases
- name: Install specific / approved docker-engine
yum:
name: docker-engine-1.12.6-1.el7.centos
state: present
# REF: https://yum.dockerproject.org/repo/main/centos/7/Packages/
- name: Install python-pip
yum:
name: python-pip
state: latest
# Tweak settings in INI files
# REF: http://docs.ansible.com/ansible/ini_file_module.html
###########################################################
# REF: http://docs.rancher.com/rancher/v1.5/en/hosts/#supported-docker-versions
- name: Set value in /etc/yum.conf to exclude auto upgrades of docker-engine so we stay on a compatible Rancher with Kubernetes version
ini_file:
dest: /etc/yum.conf
section: main
option: exclude
value: 'docker-engine'
# Restart firewalld to make sure it is running OK before changing any rules
# REF: http://docs.ansible.com/ansible/service_module.html
##########################################################
- name: Ensure the firewalld service is enabled and re-started before changing any rules
service:
name: firewalld
enabled: yes
state: restarted
# Update the firewalld configuration
# REF: http://docs.ansible.com/ansible/firewalld_module.html
############################################################
- name: Update firewall to allow port TCP 2375 for incoming Docker Cloud connections
firewalld:
port: 2375/tcp
permanent: true
immediate: yes
state: enabled
zone: public
- name: Update firewall to allow port TCP 2376 for incoming docker-machine connections
firewalld:
port: 2376/tcp
permanent: true
immediate: yes
state: enabled
zone: public
- name: Update firewall to allow port TCP 2377 for incoming Docker cluster management connections
firewalld:
port: 2377/tcp
permanent: true
immediate: yes
state: enabled
zone: public
- name: Update firewall to allow port TCP 4789 for incoming Docker overlay network connections
firewalld:
port: 4789/tcp
permanent: true
immediate: yes
state: enabled
zone: public
- name: Update firewall to allow port UDP 4789 for incoming Docker overlay network connections
firewalld:
port: 4789/udp
permanent: true
immediate: yes
state: enabled
zone: public
- name: Update firewall to allow port TCP 6783 for incoming Docker overlay network connections
firewalld:
port: 6783/tcp
permanent: true
immediate: yes
state: enabled
zone: public
- name: Update firewall to allow port UDP 6783 for incoming Docker overlay network connections
firewalld:
port: 6783/udp
permanent: true
immediate: yes
state: enabled
zone: public
- name: Update firewall to allow port TCP 7946 for incoming Docker communication among nodes
firewalld:
port: 7946/tcp
permanent: true
immediate: yes
state: enabled
zone: public
- name: Update firewall to allow port UDP 7946 for incoming Docker communication among nodes
firewalld:
port: 7946/udp
permanent: true
immediate: yes
state: enabled
zone: public
- name: Update firewall to allow ports TCP 30000-32767 for incoming Docker swarm manager PublishedPort connections
firewalld:
port: 30000-32767/tcp
permanent: true
immediate: yes
state: enabled
zone: public
# Enable and start docker
# REF: http://docs.ansible.com/ansible/service_module.html
##########################################################
- name: Enable and start (or restart) the docker service
service:
name: docker
enabled: yes
state: restarted
# Note: Verify docker via SSH command line:
# systemctl status docker
# docker run hello-world
#
# More advanced verification:
# docker run -it ubuntu bash
# cat /etc/lsb-release
#
# To run docker as a normal user, add that user to the docker group:
# usermod -aG docker your_username
# get_url - Downloads files from HTTP, HTTPS, or FTP to node
# REF: http://docs.ansible.com/ansible/get_url_module.html
############################################################
# https://github.com/docker/machine/releases
- name: Download and install docker-machine
get_url:
url: https://github.com/docker/machine/releases/download/v0.10.0/docker-machine-Linux-x86_64
dest: /usr/local/bin/docker-machine
mode: 777
force: yes
# https://github.com/docker/compose/releases
- name: Download and install docker-compose
get_url:
url: https://github.com/docker/compose/releases/download/1.12.0/docker-compose-Linux-x86_64
dest: /usr/local/bin/docker-compose
mode: 777
force: yes
# Execute command(s)
# REF: http://docs.ansible.com/ansible/command_module.html
##########################################################
- name: Use pip to update and ensure pip is at the latest version
command: /usr/bin/pip install --upgrade pip
# Use pip to install and manage Python dependencies
# REF: http://docs.ansible.com/ansible/pip_module.html
######################################################
- name: Use pip to install docker-cloud
pip:
name: docker-cloud
- name: Use pip to install docker-py
pip:
name: docker-py