-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker_install.yaml
108 lines (92 loc) · 2.85 KB
/
docker_install.yaml
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
---
- name: Install docker
hosts: all
gather_facts: yes
become: true
tasks:
- name: change DNS to Shecan
lineinfile:
path: /etc/resolv.conf
regexp: '^nameserver'
line: nameserver 185.51.200.2
- name: Update apt-get repo and cache
when: ansible_os_family == "Debian"
apt: update_cache=yes force_apt_get=yes cache_valid_time=3600
- name: upgrade all packages
when: ansible_os_family == "RedHat"
yum: name=* state=latest
- name: Install packages that allow apt to be used over HTTPS
when: ansible_os_family == "Debian"
apt:
name: "{{ packages }}"
state: present
update_cache: yes
vars:
packages:
- apt-transport-https
- ca-certificates
- curl
- gnupg-agent
- software-properties-common
- lsb-release
# - name: change DNS to Shecan
# command: 'echo "nameserver 185.51.200.2" > /etc/resolv.conf'
# - name: Add two IPv4 DNS server addresses
# community.general.nmcli:
# conn_name: my-eth1
# type: ethernet
# dns4:
# - 185.51.200.2
# state: present
- name: Add an apt signing key for Docker
when: ansible_os_family == "Debian"
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
- name: Add apt repository for stable version
when: ansible_os_family == "Debian"
apt_repository:
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable
state: present
- name: Install docker and its dependecies
when: ansible_os_family == "Debian"
apt:
name: "{{ packages }}"
state: present
update_cache: yes
vars:
packages:
- docker-ce
- docker-ce-cli
- containerd.io
notify:
- docker status
#Redhat family
- name: Add Docker yum repository
when: ansible_os_family == "RedHat"
yum_repository:
name: Docker
description: Docker Repository
file: docker
baseurl: https://download.docker.com/linux/centos/7/x86_64/stable/
enabled: yes
gpgcheck: yes
gpgkey: https://download.docker.com/linux/centos/gpg
- name: Install docker engine (RHEL/CentOS)
when: ansible_os_family == "RedHat"
yum:
name: "docker-ce-selinux-{{ docker_version }}.*"
state: present
# - name: Get version of docker
# shell: "docker version"
# register: result
# - name: Show version of docker
# debug:
# var: result
- name: Get version of docker
shell: "docker version --format {% raw %}'{{json .Client.Version}}'{% endraw %}"
# register: result
register: result
- name: Show version of docker
debug:
var: result.stdout