diff --git a/.kitchen.yml b/.kitchen.yml index 71ae22c..2475df6 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -1,7 +1,7 @@ --- driver : name : <%= if ENV['TRAVIS'] then 'localhost' else 'vagrant' end %> - box : "ubuntu/trusty64" + box : "ubuntu/bionic64" customize : cpus : 2 memory : 2048 @@ -28,4 +28,4 @@ platforms: suites: - name : default provisioner : - playbook : "test/integration/defaults/defaults.yml" \ No newline at end of file + playbook : "test/integration/defaults/defaults.yml" diff --git a/Gemfile b/Gemfile index 1546581..8e8f827 100644 --- a/Gemfile +++ b/Gemfile @@ -5,5 +5,5 @@ group :development do gem 'kitchen-vagrant' gem 'kitchen-ansiblepush' gem 'kitchen-localhost' - gem 'net-ssh', '~> 2.0' -end \ No newline at end of file + gem 'net-ssh', '~> 4.0' +end diff --git a/Readme.md b/Readme.md index bea60e8..789e209 100644 --- a/Readme.md +++ b/Readme.md @@ -6,7 +6,7 @@ An ansible role that installs docker host on ubuntu ### Role Variables ```yaml dockerhost_group : "docker" -docker_compose_version : "1.6.2" +docker_compose_version : "1.25.3" docker_compose_dir : "/opt/docker_compose" docker_compose_install : True ``` @@ -15,4 +15,4 @@ docker_compose_install : True MIT ### Contributors -* [Adham Helal](https://github.com/ahelal) \ No newline at end of file +* [Adham Helal](https://github.com/ahelal) diff --git a/defaults/main.yml b/defaults/main.yml index 486088c..7c384c6 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,7 +1,9 @@ --- dockerhost_group : "docker" -docker_compose_version : "1.6.2" +docker_compose_version : "1.25.3" docker_compose_dir : "/opt/docker_compose" docker_compose_install : True -docker_install_py_module : False \ No newline at end of file +docker_install_py_module : False + +docker_gpg_url : https://download.docker.com/linux/ubuntu/gpg diff --git a/handlers/main.yml b/handlers/main.yml index 8eb7907..0b2d6e4 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,6 +1,11 @@ --- - name: restart docker service: - name="docker" - state="restarted" + name: docker + state: restarted +- name: restart docker systemd + systemd: + name: docker + state: restarted + daemon_reload: True diff --git a/meta/main.yml b/meta/main.yml index c60cabe..1290db3 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -2,16 +2,14 @@ # meta file for ansible galaxy_info: author: Adham Helal - description: Install manage firefox + description: Install manage docker daemon license: MIT min_ansible_version: 1.9 platforms: - name: Ubuntu versions: - - all - - name: Debian - versions: - - all + - 18.04 + - 16.04 categories: - web dependencies: [] diff --git a/tasks/apt.yml b/tasks/apt.yml index 52ab8f8..0393b1a 100644 --- a/tasks/apt.yml +++ b/tasks/apt.yml @@ -9,20 +9,19 @@ with_items: - apt-transport-https - ca-certificates - - "linux-image-extra-{{ ansible_kernel }}" - name: Add apt repo GPG apt_key: - keyserver="{{ dockerhost_keyserver }}" id="{{ dockerhost_id }}" + url="{{ docker_gpg_url }}" - name: Add docker apt repo apt_repository: - repo="deb https://apt.dockerproject.org/repo ubuntu-{{ ansible_lsb.codename }} main" + repo="deb https://download.docker.com/linux/ubuntu {{ ansible_lsb.codename }} stable" update_cache="yes" - name: Purge the old repo (lxc-docker) apt: pkg="lxc-docker" state="absent" - purge="true" \ No newline at end of file + purge="true" diff --git a/tasks/main.yml b/tasks/main.yml index 790ab4d..cfe9f15 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -4,11 +4,11 @@ - name: Add docker group group: - name="{{ dockerhost_group }}" - system="True" - state="present" + name: "{{ dockerhost_group }}" + system: True + state: present -- name: Include apt tasks +- name: Apt tasks include: apt.yml - name: Include docker-py @@ -17,21 +17,32 @@ - name: Install docker engine apt: - pkg="docker-engine" + pkg: "docker-ce" - name: Include docker-compose.yml include: docker-compose.yml when: docker_compose_install -- name: Include docker conf +- name: Create docker conf template: - src=docker_conf_ubuntu_14.04.j2 - dest=/etc/default/docker + src: docker_conf.j2 + dest: /etc/default/docker + when: ansible_service_mgr != 'systemd' notify: - - restart docker + - restart docker + +- name: Create docker systemd unit file + template: + src: docker_systemd_service.j2 + dest: /etc/systemd/system/docker.service + when: ansible_service_mgr == 'systemd' + notify: + - restart docker systemd + +- meta: flush_handlers - name: Ensure docker is running and starts by default service: - name="docker" - state="started" - enabled=True + name: docker + state: started + enabled: True diff --git a/tasks/users.yml b/tasks/users.yml deleted file mode 100644 index b146a4d..0000000 --- a/tasks/users.yml +++ /dev/null @@ -1 +0,0 @@ -users.yml \ No newline at end of file diff --git a/templates/docker_conf_ubuntu_14.04.j2 b/templates/docker_conf.j2 similarity index 100% rename from templates/docker_conf_ubuntu_14.04.j2 rename to templates/docker_conf.j2 diff --git a/templates/docker_systemd_service.j2 b/templates/docker_systemd_service.j2 new file mode 100644 index 0000000..a12c782 --- /dev/null +++ b/templates/docker_systemd_service.j2 @@ -0,0 +1,38 @@ +[Unit] +Description=Docker Application Container Engine +Documentation=https://docs.docker.com +After=network-online.target docker.socket firewalld.service +Wants=network-online.target +Requires=docker.socket + +[Service] +Type=notify +# the default is not to use systemd for cgroups because the delegate issues still +# exists and systemd currently does not support the cgroup feature set required +# for containers run by docker +{% if dockerhost_docker_opts is defined %} +ExecStart=/usr/bin/dockerd -H fd:// {{dockerhost_docker_opts}} +{% else %} +ExecStart=/usr/bin/dockerd -H fd:// +{% endif %} +ExecReload=/bin/kill -s HUP $MAINPID +LimitNOFILE=1048576 +# Having non-zero Limit*s causes performance problems due to accounting overhead +# in the kernel. We recommend using cgroups to do container-local accounting. +LimitNPROC=infinity +LimitCORE=infinity +# Uncomment TasksMax if your systemd version supports it. +# Only systemd 226 and above support this version. +#TasksMax=infinity +TimeoutStartSec=0 +# set delegate yes so that systemd does not reset the cgroups of docker containers +Delegate=yes +# kill only the docker process, not all processes in the cgroup +KillMode=process +# restart the docker process if it exits prematurely +Restart=on-failure +StartLimitBurst=3 +StartLimitInterval=60s + +[Install] +WantedBy=multi-user.target diff --git a/test/integration/defaults/serverspec/default_spec.rb b/test/integration/defaults/serverspec/default_spec.rb index 0fcc962..49430b3 100644 --- a/test/integration/defaults/serverspec/default_spec.rb +++ b/test/integration/defaults/serverspec/default_spec.rb @@ -5,5 +5,5 @@ # Default version describe command('docker --version') do - its(:stdout) { should contain('1.10') } + its(:stdout) { should contain('19.03.5') } end diff --git a/test/integration/defaults/serverspec/main.yml b/test/integration/defaults/serverspec/main.yml index d11fa41..49430b3 100644 --- a/test/integration/defaults/serverspec/main.yml +++ b/test/integration/defaults/serverspec/main.yml @@ -5,5 +5,5 @@ set :backend, :exec # Default version describe command('docker --version') do - its(:stdout) { should contain('1.9') } + its(:stdout) { should contain('19.03.5') } end diff --git a/test/integration/docker-py/serverspec/default_spec.rb b/test/integration/docker-py/serverspec/default_spec.rb index 0fcc962..49430b3 100644 --- a/test/integration/docker-py/serverspec/default_spec.rb +++ b/test/integration/docker-py/serverspec/default_spec.rb @@ -5,5 +5,5 @@ # Default version describe command('docker --version') do - its(:stdout) { should contain('1.10') } + its(:stdout) { should contain('19.03.5') } end diff --git a/vars/main.yml b/vars/main.yml index 35dca66..e5665b6 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,7 +1,7 @@ --- -dockerhost_keyserver : "hkps://keys.openpgp.org" -dockerhost_id : "58118E89F3A912897C070ADBF76221572C52609D" +dockerhost_keyserver : "https://download.docker.com/linux/ubuntu/gpg" +dockerhost_id : "7EA0A9C3F273FCD8" docker_compose_file : "docker-compose-Linux-{{ ansible_userspace_architecture }}-{{ docker_compose_version }}" docker_compose_url : "https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-Linux-{{ ansible_userspace_architecture }}"