-
Notifications
You must be signed in to change notification settings - Fork 2
/
docker-host.yml
177 lines (149 loc) · 5.7 KB
/
docker-host.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
---
# With massive help from:
# - https://github.com/bryfry/ansible-docker/blob/master/docker.yml
# - https://github.com/bobbyrenwick/ansible-pip/blob/master/tasks/main.yml
- hosts: all
sudo: yes
vars:
docker_host_ip: 0.0.0.0
docker_host_port: 2375
docker_version: 1.7.0
docker_py_version: 1.2.3
python: python
pip: pip
pip_version:
pip_download_dest: /tmp
tasks:
- name: Ubuntu | Adding Docker repository key
apt_key: >
url="https://get.docker.io/gpg" id="A88D21E9" state=present
when: ansible_os_family == 'Debian'
- name: Ubuntu | Adding Docker repository
apt_repository: >
repo='deb http://get.docker.io/ubuntu docker main'
update_cache=yes
state=present
when: ansible_os_family == 'Debian'
- name: Ubuntu | Installing Docker and Dependencies
apt: name="{{ item }}" state=present
with_items:
- apt-transport-https
- "lxc-docker-{{ docker_version }}"
when: ansible_os_family == 'Debian'
- name: Ubuntu | Remove system pip if it exists
apt: name=python-pip state=absent
when: ansible_os_family == 'Debian'
- name: check to see if pip is already installed
command: "{{ pip }} --version"
ignore_errors: true
changed_when: false
register: pip_is_installed
changed_when: false
- name: download pip
get_url: url=https://bootstrap.pypa.io/get-pip.py dest={{ pip_download_dest }}
when: pip_is_installed.rc != 0
- name: install pip
command: "{{ python }} {{ pip_download_dest }}/get-pip.py"
sudo: yes
when: pip_is_installed.rc != 0
- name: check to see if pip is installed at the correct version
shell: "{{ pip }} --version | awk '{print $2}'"
register: pip_installed_version
changed_when: false
when: pip_version != None or pip_version != "LATEST"
- name: install required version of pip
command: "{{ pip }} install pip=={{ pip_version }}"
sudo: yes
when: pip_version != None and pip_installed_version.stdout != pip_version and pip_version != "LATEST"
- name: Upgrade to latest version of pip
command: "{{ pip }} install -U pip"
register: pip_latest_output
sudo: yes
changed_when: pip_latest_output.stdout.find('Requirement already up-to-date') == -1
when: pip_version == None or pip_version == "LATEST"
- name: CentOS | get epel-repo rpm RHEL6
get_url:
dest: /tmp/epel-release.rpm
url: http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
when: ansible_os_family == 'RedHat'
- name: CentOS | install epel-repo rpm
yum: pkg=/tmp/epel-release.rpm state=installed
when: ansible_os_family == 'RedHat'
register: epel_enabled
- name: CentOS | update yum cache
command: yum makecache
when: ansible_os_family == 'RedHat'
register: epel_enabled | changed
- name: CentOS | Installing Docker and Dependencies
yum: name={{ item }} enablerepo=epel state=present
with_items:
- "docker-io"
- python-pip
- libselinux-python
when: ansible_os_family == 'RedHat'
- name: Installing docker-py for ansible docker module
pip: name=docker-py=={{ docker_py_version }} state=present
- name: Debian | Expose docker host
lineinfile: >
dest=/etc/default/docker
regexp="^DOCKER_OPTS"
line='DOCKER_OPTS="-H unix:///var/run/docker.sock -H tcp://{{ docker_host_ip }}:{{ docker_host_port }}"'
when: expose_docker_host
tags: [test]
when: ansible_os_family == 'Debian'
- name: CentOS | Expose docker host
lineinfile:
dest: /etc/sysconfig/docker
regexp: "^other_args"
line: 'other_args="-H unix:///var/run/docker.sock -H tcp://{{ docker_host_ip }}:{{ docker_host_port }}"'
when: expose_docker_host
tags: [test]
when: ansible_os_family == 'RedHat'
- name: Restart docker service / daemon
service: name=docker state=restarted
- hosts: all
sudo: yes
vars:
expose_docker_host: true
squash_version: v0.0.11
squash_file: "docker-squash-linux-amd64-{{ squash_version }}.tar.gz"
squash_url: "https://github.com/jwilder/docker-squash/releases/download/{{ squash_version }}/{{ squash_file }}"
tasks:
- name: Route traffic locally to docker
sudo: true
sudo_user: "{{ local_user }}"
shell: sudo route -nv add -net {{ ansible_docker0.ipv4.address }}/16 {{ bridge_network }}
delegate_to: 127.0.0.1
when: expose_docker_host
tags: [test]
- name: Adding vagrant user to docker group
user: name=vagrant append=yes groups=docker state=present
- name: download docker-squash
get_url: url={{ squash_url }} dest=/tmp mode=0644
- name: unpack docker-squash
unarchive: src=/tmp/{{ squash_file }} dest=/usr/local/bin copy=no
# - name: smash grub
# lineinfile: >
# dest=/etc/default/grub
# regexp='^GRUB_CMDLINE_LINUX='
# line='GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"'
# register: grub_edit
# - name: updatin grub
# command: update-grub
# when: grub_edit|changed
# - name: ufw forwardin
# lineinfile: >
# dest=/etc/default/ufw
# regexp="^DEFAULT_FORWARD_POLICY="
# line="DEFAULT_FORWARD_POLICY=\"ACCEPT\""
# - name: restart machine
# command: shutdown -r now "Ansible updates triggered"
# async: 0
# poll: 0
# ignore_errors: true
# when: grub_edit|changed
# - name: waiting for server to come back
# local_action: >
# wait_for host={{ ansible_ssh_host }}
# port={{ansible_ssh_port}} delay=30 state=started
# sudo: false