Migrate lf-ansible docker-install role 69/8969/7
authorThanh Ha <thanh.ha@linuxfoundation.org>
Wed, 21 Feb 2018 20:24:55 +0000 (15:24 -0500)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Wed, 21 Feb 2018 21:29:23 +0000 (16:29 -0500)
Move in docker-install role from lf-ansible.

Change-Id: I68328c65be64855d8c49b463a215c60116269f2d
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
README.md
defaults/main.yml
files/daemon.json [new file with mode: 0644]
molecule/default/create.yml
molecule/default/destroy.yml
molecule/default/molecule.yml
tasks/main.yml

index 9fff337..080cd3c 100644 (file)
--- a/README.md
+++ b/README.md
@@ -11,7 +11,7 @@ None.
 Role Variables
 --------------
 
-None.
+mtu: Configures the mtu to assign to the Docker port.
 
 Dependencies
 ------------
index 4d941a4..a37d6a8 100644 (file)
@@ -1,2 +1,2 @@
 ---
-# defaults file for docker-install
+mtu: 1500
diff --git a/files/daemon.json b/files/daemon.json
new file mode 100644 (file)
index 0000000..607e6fa
--- /dev/null
@@ -0,0 +1,9 @@
+{
+  "bip": "10.250.0.254/24",
+  "hosts": [
+    "tcp://0.0.0.0:5555",
+    "unix:///var/run/docker.sock"
+  ],
+  "mtu": 1500,
+  "selinux-enabled": true
+}
index bfb2149..780f659 100644 (file)
@@ -3,7 +3,7 @@
   hosts: localhost
   connection: local
   gather_facts: false
-  no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}"
+  no_log: false
   vars:
     molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}"
     molecule_ephemeral_directory: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}"
index 3ce7478..f2a60f9 100644 (file)
@@ -3,7 +3,7 @@
   hosts: localhost
   connection: local
   gather_facts: false
-  no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}"
+  no_log: false
   vars:
     molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}"
     molecule_yml: "{{ lookup('file', molecule_file) | molecule_from_yaml }}"
index f5e3b11..3423388 100644 (file)
@@ -6,8 +6,12 @@ driver:
 lint:
   name: yamllint
 platforms:
-  - name: instance
-    image: centos:7
+  # Disable centos7 tests until we figure out how to get systemctl working
+  # in a Docker container reliabily.
+  # - name: centos7
+  #   image: centos:7
+  - name: ubuntu1604
+    image: ubuntu:16.04
 provisioner:
   name: ansible
   lint:
index 3807b4a..a952365 100644 (file)
@@ -1,2 +1,70 @@
 ---
-# tasks file for docker-install
+- name: Install Docker (RedHat)
+  block:
+    - name: Install Docker requirements
+      yum: 'name={{item}} state=present'
+      with_items:
+        - device-mapper-persistent-data
+        - lvm2
+    - name: Add Docker repository
+      get_url:
+        url: https://download.docker.com/linux/centos/docker-ce.repo
+        dest: /etc/yum.repos.d/docker-ce.repo
+        mode: 0644
+    - name: Install Docker CE
+      yum: name=docker-ce state=present update_cache=yes
+  when: ansible_os_family == 'RedHat'
+  become: true
+
+- name: Install Docker (Ubuntu)
+  block:
+    - name: Install Docker requirements
+      apt: 'name=apt-transport-https state=present'
+    - name: Add Docker apt-key
+      apt_key:
+        url: https://download.docker.com/linux/ubuntu/gpg
+        state: present
+    - name: Add Docker apt-repository
+      apt_repository:
+        repo: 'deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ansible_distribution_release}} stable'
+        state: present
+    - name: Install Docker CE
+      apt: name=docker-ce state=present update_cache=yes
+  when: ansible_distribution == 'Ubuntu'
+  become: true
+
+- name: Copy LF Docker configuration
+  block:
+    - name: Ensure /etc/docker directory exists
+      file:
+        path: /etc/docker
+        state: directory
+        mode: 0700
+    - name: Copy LF Docker configuration
+      copy:
+        src: daemon.json
+        dest: /etc/docker/daemon.json
+        owner: root
+        group: root
+      mode: 0600
+    - name: 'Set mtu to {{mtu}}'
+      lineinfile:
+        path: /etc/docker/daemon.json
+        regexp: '^  "mtu":'
+        line: '  "mtu": {{mtu}},'
+  become: true
+
+# The systemd file on Ubuntu system passes `-H fd://` which seems to break
+# and prevent Docker from coming online. Use the same ExecStart line as
+# Docker CE CentOS does to fix the file.
+- name: Fix broken systemd file on Ubuntu
+  lineinfile:
+    path: /lib/systemd/system/docker.service
+    regexp: '^ExecStart='
+    line: 'ExecStart=/usr/bin/dockerd'
+  when: ansible_distribution == 'Ubuntu'
+  become: true
+
+- name: Enable Docker service
+  service: name=docker enabled=true
+  become: true