Skip to content

Commit

Permalink
Merge pull request #8 from 5monkeys/ubuntu18-compatibility
Browse files Browse the repository at this point in the history
Make the playbook Ubuntu 18 compatible
  • Loading branch information
kjagiello authored Nov 25, 2019
2 parents 238e89c + f7d9899 commit 6565b69
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 12 deletions.
2 changes: 1 addition & 1 deletion molecule/default/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
Expand Down
10 changes: 9 additions & 1 deletion molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@ driver:
lint:
name: yamllint
platforms:
- name: instance
- name: ubuntu16
image: ubuntu:16.04
cap_add:
- SYS_ADMIN
volume_mounts:
- "/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
Expand Down
4 changes: 2 additions & 2 deletions molecule/default/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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_*
Expand Down
15 changes: 9 additions & 6 deletions molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 12 additions & 2 deletions tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tasks/tls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6565b69

Please sign in to comment.