Skip to content

Commit

Permalink
master Add docker running task and add check on running status test
Browse files Browse the repository at this point in the history
  • Loading branch information
kirill-zak committed Jun 5, 2020
1 parent 9e5db01 commit 362a0e5
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 9 deletions.
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
---
language: python

services:
- docker

python:
- "3.7"

env:
- UBUNTU_IMAGE_TAG: bionic
- MOLECULE_DISTRO: ubuntu2004
- MOLECULE_DISTRO: ubuntu1804
- MOLECULE_DISTRO: ubuntu1604

install:
- pip install testinfra molecule docker

script:
- molecule test

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ N/A

* `docker_gpg_key`: GPG key for Docker repository
* `docker_ubuntu_release`: Version of Ubuntu release
* `docker_users`: a list of users to add to the docker group. They will not be evaluated until a session is created.
* `docker_users`: A list of users to add to the docker group. They will not be evaluated until a session is created.
* `docker_service_state`: Docker service state
* `docker_service_enabled`: Docker service enable status

## Dependencies

Expand Down
2 changes: 2 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

docker_gpg_key: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88
docker_ubuntu_release: bionic
docker_service_state: started
docker_service_enabled: true

docker_users:
- root
21 changes: 21 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
---
- name: Converge
hosts: all
become: true

pre_tasks:
- name: Update apt cache
apt:
update_cache: true
cache_valid_time: 600
changed_when: false

- name: Wait for systemd to complete initialization
command: systemctl is-system-running
register: systemctl_status
until: >
'running' in systemctl_status.stdout or
'degraded' in systemctl_status.stdout
retries: 30
delay: 5
when: ansible_service_mgr == 'systemd'
changed_when: false
failed_when: systemctl_status.rc > 1

tasks:
- name: "Include ansible-docker"
include_role:
Expand Down
6 changes: 5 additions & 1 deletion molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ driver:
name: docker
platforms:
- name: instance
image: docker.io/pycontribs/ubuntu:latest
image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2004}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
pre_build_image: true
provisioner:
name: ansible
Expand Down
8 changes: 7 additions & 1 deletion molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ def test_hosts_file(host):
def test_docker_is_installed(host):
docker = host.package("docker-ce")

assert docker.is_installed
assert docker.is_installed

def test_docker_is_enabled_and_is_running(host):
service = host.service("docker")

assert service.is_running
assert service.is_enabled
13 changes: 8 additions & 5 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,17 @@
- docker-ce-cli
- containerd.io
state: present
register: result
until: result is success
retries: 5
delay: 5

- name: Ensure Docker is started and enabled at boot.
service:
name: docker
state: "{{ docker_service_state }}"
enabled: "{{ docker_service_enabled }}"

- name: Add user to Docker group
user:
name: "{{ item }}"
groups: docker
append: true
loop: "{{ docker_users }}"
with_items: "{{ docker_users }}"
when: docker_users| length > 0

0 comments on commit 362a0e5

Please sign in to comment.