From: Thanh Ha Date: Wed, 21 Feb 2018 20:24:55 +0000 (-0500) Subject: Migrate lf-ansible docker-install role X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=4e694d93cb32456476f80e17f22faa7fec80e808;p=ansible%2Froles%2Fdocker-install.git Migrate lf-ansible docker-install role Move in docker-install role from lf-ansible. Change-Id: I68328c65be64855d8c49b463a215c60116269f2d Signed-off-by: Thanh Ha --- diff --git a/README.md b/README.md index 9fff337..080cd3c 100644 --- 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 ------------ diff --git a/defaults/main.yml b/defaults/main.yml index 4d941a4..a37d6a8 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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 index 0000000..607e6fa --- /dev/null +++ b/files/daemon.json @@ -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 +} diff --git a/molecule/default/create.yml b/molecule/default/create.yml index bfb2149..780f659 100644 --- a/molecule/default/create.yml +++ b/molecule/default/create.yml @@ -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') }}" diff --git a/molecule/default/destroy.yml b/molecule/default/destroy.yml index 3ce7478..f2a60f9 100644 --- a/molecule/default/destroy.yml +++ b/molecule/default/destroy.yml @@ -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 }}" diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index f5e3b11..3423388 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -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: diff --git a/tasks/main.yml b/tasks/main.yml index 3807b4a..a952365 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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