diff --git a/molecule/default/Dockerfile.j2 b/molecule/default/Dockerfile.j2 index 0a60553..a5b6739 100644 --- a/molecule/default/Dockerfile.j2 +++ b/molecule/default/Dockerfile.j2 @@ -6,7 +6,7 @@ FROM {{ item.registry.url }}/{{ item.image }} FROM {{ item.image }} {% endif %} -RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates systemd && apt-get clean; \ elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \ elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \ diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 4f1a1bf..833f546 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -6,7 +6,7 @@ driver: lint: name: yamllint platforms: - - name: instance + - name: ubuntu16 image: ubuntu:16.04 cap_add: - SYS_ADMIN @@ -14,6 +14,14 @@ platforms: - "/sys/fs/cgroup:/sys/fs/cgroup:ro" command: /sbin/init privileged: true + - name: ubuntu18 + image: ubuntu:18.04 + cap_add: + - SYS_ADMIN + volume_mounts: + - "/sys/fs/cgroup:/sys/fs/cgroup:ro" + command: /sbin/init + privileged: true provisioner: name: ansible diff --git a/molecule/default/playbook.yml b/molecule/default/playbook.yml index 62976f7..3e7196d 100644 --- a/molecule/default/playbook.yml +++ b/molecule/default/playbook.yml @@ -7,9 +7,9 @@ apt: update_cache: true cache_valid_time: 600 - - name: Update apt cache + - name: Install required packages apt: - name: "iproute" + name: "iproute2" state: present - name: Gather facts now that prerequisite packages are installed setup: filter=ansible_* diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py index eedd64a..c784dd6 100644 --- a/molecule/default/tests/test_default.py +++ b/molecule/default/tests/test_default.py @@ -3,12 +3,15 @@ import testinfra.utils.ansible_runner testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + os.environ["MOLECULE_INVENTORY_FILE"] +).get_hosts("all") -def test_hosts_file(host): - f = host.file('/etc/hosts') +def test_docker_running_and_enabled(host): + docker = host.service("docker") + assert docker.is_running + assert docker.is_enabled - assert f.exists - assert f.user == 'root' - assert f.group == 'root' + +def test_able_to_access_docker_without_root(host): + assert "docker" in host.user("ubuntu").groups diff --git a/tasks/install.yml b/tasks/install.yml index 7faa8bc..7db553f 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -14,17 +14,27 @@ state: present when: docker_install_kernel_extras|bool -- name: Install system dependencies +- name: Install common system dependencies apt: name: - "apt-transport-https" - "ca-certificates" - - "gnupg-curl" + - "gnupg2" - "software-properties-common" - "python-pip" force_apt_get: true state: present +- name: Install Ubuntu 16 system dependencies + when: | + ansible_facts['distribution'] == "Ubuntu" + and ansible_facts['distribution_major_version'] == "16" + apt: + name: + - "gnupg-curl" + force_apt_get: true + state: present + - name: Add gpg key apt_key: keyserver: https://download.docker.com/linux/ubuntu/gpg diff --git a/tasks/tls.yml b/tasks/tls.yml index 3272a95..5076b6f 100644 --- a/tasks/tls.yml +++ b/tasks/tls.yml @@ -139,3 +139,9 @@ tags: - tls-client - tls-download + # The tests may fail sometimes here because due to a race condition caused + # by files being downloaded to the same place by the different platforms + # molecule is run against. There seem to be no supported way of separating + # the workspaces between the platforms, so we have to skip this task when + # running tests. + - molecule-notest