Parameterize arch with ansible_architecture
[ansible/roles/docker-install.git] / tasks / main.yml
1 ---
2 - name: "Checking for x86_64"
3   set_fact:
4     host_arch: "amd64"
5   when: "'x86_64' in ansible_architecture"
6
7 - name: "Checking for aarch64"
8   set_fact:
9     host_arch: "armhf"
10   when: "'aarch64' in ansible_architecture"
11
12 - name: Install Docker (RedHat)
13   block:
14     - name: Install Docker requirements
15       yum:
16         name:
17           - device-mapper-persistent-data
18           - lvm2
19         state: present
20     - name: Add Docker repository
21       get_url:
22         url: https://download.docker.com/linux/centos/docker-ce.repo
23         dest: /etc/yum.repos.d/docker-ce.repo
24         mode: 0644
25     - name: Install Docker CE
26       yum: name=docker-ce state=present update_cache=yes
27   when: ansible_os_family == 'RedHat'
28   become: true
29
30 - name: Install Docker (Ubuntu)
31   block:
32     - name: Install Docker requirements
33       apt:
34         name:
35           - apt-transport-https
36           - ca-certificates
37           - curl
38           - software-properties-common
39         state: present
40     - name: Add Docker apt-key
41       apt_key:
42         url: https://download.docker.com/linux/ubuntu/gpg
43         state: present
44     - name: Add Docker apt-repository
45       apt_repository:
46         repo: 'deb [arch={{host_arch}}] https://download.docker.com/linux/ubuntu {{ansible_distribution_release}} stable'
47         state: present
48     - name: Install Docker CE
49       apt: name=docker-ce state=present update_cache=yes
50   when: ansible_distribution == 'Ubuntu'
51   become: true
52
53 - name: Copy LF Docker configuration
54   block:
55     - name: Ensure /etc/docker directory exists
56       file:
57         path: /etc/docker
58         state: directory
59         mode: 0700
60     - name: Copy LF Docker configuration
61       copy:
62         src: daemon.json
63         dest: /etc/docker/daemon.json
64         owner: root
65         group: root
66       mode: 0600
67     - name: 'Set mtu to {{mtu}}'
68       lineinfile:
69         path: /etc/docker/daemon.json
70         regexp: '^  "mtu":'
71         line: '  "mtu": {{mtu}},'
72   become: true
73
74 # The systemd file on Ubuntu system passes `-H fd://` which seems to break
75 # and prevent Docker from coming online. Use the same ExecStart line as
76 # Docker CE CentOS does to fix the file.
77 - name: Fix broken systemd file on Ubuntu
78   lineinfile:
79     path: /lib/systemd/system/docker.service
80     regexp: '^ExecStart='
81     line: 'ExecStart=/usr/bin/dockerd'
82   when: ansible_distribution == 'Ubuntu'
83   become: true
84
85 - name: Enable Docker service
86   service: name=docker enabled=true
87   when: docker_service_enable
88   become: true