summaryrefslogtreecommitdiffstats
path: root/ansible_collections/google/cloud/molecule
diff options
context:
space:
mode:
Diffstat (limited to 'ansible_collections/google/cloud/molecule')
-rw-r--r--ansible_collections/google/cloud/molecule/gcloud/Dockerfile.j2111
-rw-r--r--ansible_collections/google/cloud/molecule/gcloud/archive_playbook.yml15
-rw-r--r--ansible_collections/google/cloud/molecule/gcloud/converge.yml26
-rw-r--r--ansible_collections/google/cloud/molecule/gcloud/files/override.conf2
-rw-r--r--ansible_collections/google/cloud/molecule/gcloud/molecule.yml26
-rw-r--r--ansible_collections/google/cloud/molecule/gcloud/package_playbook.yml13
-rw-r--r--ansible_collections/google/cloud/molecule/gcloud/tests/test_default.py23
-rw-r--r--ansible_collections/google/cloud/molecule/gcloud/verify.yml9
-rw-r--r--ansible_collections/google/cloud/molecule/gcsfuse/Dockerfile.j2111
-rw-r--r--ansible_collections/google/cloud/molecule/gcsfuse/converge.yml14
-rw-r--r--ansible_collections/google/cloud/molecule/gcsfuse/files/override.conf2
-rw-r--r--ansible_collections/google/cloud/molecule/gcsfuse/molecule.yml26
-rw-r--r--ansible_collections/google/cloud/molecule/gcsfuse/tests/test_default.py23
-rw-r--r--ansible_collections/google/cloud/molecule/gcsfuse/verify.yml9
14 files changed, 410 insertions, 0 deletions
diff --git a/ansible_collections/google/cloud/molecule/gcloud/Dockerfile.j2 b/ansible_collections/google/cloud/molecule/gcloud/Dockerfile.j2
new file mode 100644
index 000000000..5c2401ca8
--- /dev/null
+++ b/ansible_collections/google/cloud/molecule/gcloud/Dockerfile.j2
@@ -0,0 +1,111 @@
+# Molecule managed
+
+{% if item.registry is defined %}
+FROM {{ item.registry.url }}/{{ item.image }}
+{% else %}
+FROM {{ item.image }}
+{% endif %}
+ENV container=docker
+
+{# Initial Package Installs and Container Prep #}
+{% if item.image.split(':', 1)[0] in ["ubuntu"] %}
+RUN apt-get update \
+ && apt-get install -y --no-install-recommends \
+ locales software-properties-common rsyslog systemd systemd-cron sudo \
+ iproute2
+RUN sed -i 's/^\($ModLoad imklog\)/#\1/' /etc/rsyslog.conf
+{% elif item.image.split(':', 1)[0] in ["debian"] %}
+RUN apt-get update \
+ && apt-get install -y --no-install-recommends \
+ sudo systemd systemd-sysv \
+ build-essential wget
+{% elif item.image.split(':', 1)[0] in ["centos"] %}
+{% if item.image in ["centos:7"] %}
+RUN yum makecache fast && yum -y install deltarpm \
+{% elif item.image in ["centos:8"] %}
+RUN yum makecache --timer \
+{% endif %}
+ && yum -y install epel-release \
+ && yum -y update \
+ && yum -y install sudo which
+{% endif %}
+
+
+{# Install of Python2 #}
+{% if item.image in ["ubuntu:16.04"] %}
+RUN apt-get update \
+ && apt-get install -y --no-install-recommends python-setuptools wget \
+ && wget https://bootstrap.pypa.io/get-pip.py \
+ && python get-pip.py
+{% elif item.image in ["debian:9"] %}
+RUN apt-get update \
+ && apt-get install -y --no-install-recommends libffi-dev libssl-dev \
+ python-pip python-dev python-setuptools python-wheel
+{% elif item.image in ["centos:7"] %}
+RUN yum -y install python-pip
+{% endif %}
+
+{# Install of Python3 #}
+{% if item.image in ["ubuntu:18.04", "ubuntu:20.04", "debian:10"] %}
+RUN apt-get update \
+ && apt-get install -y --no-install-recommends \
+ apt-utils python3-setuptools python3-pip
+{% endif %}
+{% if item.image in ["centos:8"] %}
+RUN yum -y install hostname python3 python3-pip
+{% endif %}
+
+{# Steps for cleanup #}
+{% if item.image.split(':', 1)[0] in ["ubuntu", "debian"] %}
+RUN rm -Rf /var/lib/apt/lists/* \
+ && rm -Rf /usr/share/doc && rm -Rf /usr/share/man \
+ && apt-get clean
+{% elif item.image.split(':', 1)[0] in ["centos"] %}
+RUN yum clean all
+{% endif %}
+
+{# Steps for clenaup of systemd #}
+{% if item.image in ["centos:7", "centos:8", "debian:9"] %}
+RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \
+ systemd-tmpfiles-setup.service ] || rm -f $i; done); \
+ rm -f /lib/systemd/system/multi-user.target.wants/*;\
+ rm -f /etc/systemd/system/*.wants/*;\
+ rm -f /lib/systemd/system/local-fs.target.wants/*; \
+ rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
+ rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
+ rm -f /lib/systemd/system/basic.target.wants/*;\
+ rm -f /lib/systemd/system/anaconda.target.wants/*; \
+ mkdir -p /run/systemd/system
+{% endif %}
+{% if item.image in ["ubuntu:18.04", "ubuntu:20.04"] %}
+# Remove unnecessary getty and udev targets that result in high CPU usage when using
+# multiple containers with Molecule (https://github.com/ansible/molecule/issues/1104)
+RUN rm -f /lib/systemd/system/systemd*udev* \
+ && rm -f /lib/systemd/system/getty.target
+{% endif %}
+
+
+{% if item.image in ["centos:7", "centos:8"] %}
+# Disable requiretty.
+RUN sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers
+{% endif %}
+
+{% if item.image.split(':', 1)[0] not in ["centos", "debian"] %}
+# Fix potential UTF-8 errors with ansible-test.
+RUN locale-gen en_US.UTF-8
+{% endif %}
+
+# Install Ansible inventory file.
+RUN mkdir -p /etc/ansible
+RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts
+
+{% if item.image in ["centos:7", "centos:8", "debian:9", "debian:10"] %}
+VOLUME ["/sys/fs/cgroup"]
+{% elif item.image in ["ubuntu:16.04", "ubuntu:18.04", "ubuntu:20.04"] %}
+VOLUME ["/sys/fs/cgroup", "/tmp", "/run"]
+{% endif %}
+{% if item.image in ["centos:7", "centos:8"] %}
+CMD ["/usr/sbin/init"]
+{% elif item.image in ["ubuntu:16.04", "ubuntu:18.04", "ubuntu:20.04", "debian:9", "debian:10"] %}
+CMD ["/lib/systemd/systemd"]
+{% endif %}
diff --git a/ansible_collections/google/cloud/molecule/gcloud/archive_playbook.yml b/ansible_collections/google/cloud/molecule/gcloud/archive_playbook.yml
new file mode 100644
index 000000000..97c84afa7
--- /dev/null
+++ b/ansible_collections/google/cloud/molecule/gcloud/archive_playbook.yml
@@ -0,0 +1,15 @@
+---
+- name: Converge
+ hosts: all
+ pre_tasks:
+ - name: Install gpg for apt_key
+ ansible.builtin.apt:
+ name: gnupg
+ update_cache: true
+ when: ansible_os_family | lower == "debian"
+ roles:
+ - role: google.cloud.gcloud
+ gcloud_install_type: archive
+ gcloud_command_completion: true
+ gcloud_additional_components:
+ - cloud-build-local
diff --git a/ansible_collections/google/cloud/molecule/gcloud/converge.yml b/ansible_collections/google/cloud/molecule/gcloud/converge.yml
new file mode 100644
index 000000000..869474587
--- /dev/null
+++ b/ansible_collections/google/cloud/molecule/gcloud/converge.yml
@@ -0,0 +1,26 @@
+---
+- name: Converge
+ hosts: all
+ pre_tasks:
+ - name: Update package cache
+ ansible.builtin.package:
+ update_cache: "yes"
+ changed_when: false
+ register: task_result
+ until: task_result is success
+ retries: 10
+ delay: 2
+ - name: Create containerd folder
+ ansible.builtin.file:
+ path: /etc/systemd/system/containerd.service.d
+ state: directory
+ mode: 0755
+ when: ansible_service_mgr == "systemd"
+ - name: Override file for containerd
+ ansible.builtin.copy:
+ src: files/override.conf
+ dest: /etc/systemd/system/containerd.service.d/override.conf
+ mode: 0644
+ when: ansible_service_mgr == "systemd"
+ roles:
+ - role: google.cloud.gcloud
diff --git a/ansible_collections/google/cloud/molecule/gcloud/files/override.conf b/ansible_collections/google/cloud/molecule/gcloud/files/override.conf
new file mode 100644
index 000000000..76864e209
--- /dev/null
+++ b/ansible_collections/google/cloud/molecule/gcloud/files/override.conf
@@ -0,0 +1,2 @@
+[Service]
+ExecStartPre=
diff --git a/ansible_collections/google/cloud/molecule/gcloud/molecule.yml b/ansible_collections/google/cloud/molecule/gcloud/molecule.yml
new file mode 100644
index 000000000..7b7ab5473
--- /dev/null
+++ b/ansible_collections/google/cloud/molecule/gcloud/molecule.yml
@@ -0,0 +1,26 @@
+---
+dependency:
+ name: galaxy
+driver:
+ name: docker
+lint: |
+ set -e
+ yamllint .
+ ansible-lint
+platforms:
+ - name: instance
+ image: ubuntu:18.04
+ privileged: true
+ ansible.builtin.command: "/lib/systemd/systemd"
+ volumes:
+ - /sys/fs/cgroup:/sys/fs/cgroup:ro
+ - name: instance
+ image: debian:9
+ privileged: true
+ ansible.builtin.command: "/lib/systemd/systemd"
+ volumes:
+ - /sys/fs/cgroup:/sys/fs/cgroup:ro
+provisioner:
+ name: ansible
+ playbooks:
+ converge: ${MOLECULE_PLAYBOOK:-converge.yml}
diff --git a/ansible_collections/google/cloud/molecule/gcloud/package_playbook.yml b/ansible_collections/google/cloud/molecule/gcloud/package_playbook.yml
new file mode 100644
index 000000000..68af24e6f
--- /dev/null
+++ b/ansible_collections/google/cloud/molecule/gcloud/package_playbook.yml
@@ -0,0 +1,13 @@
+---
+- name: Converge
+ hosts: all
+ pre_tasks:
+ - name: Install gpg for apt_key
+ ansible.builtin.apt:
+ name: gnupg
+ update_cache: true
+ when: ansible_os_family | lower == "debian"
+ roles:
+ - role: google.cloud.gcloud
+ gcloud_additional_components:
+ - cloud-build-local
diff --git a/ansible_collections/google/cloud/molecule/gcloud/tests/test_default.py b/ansible_collections/google/cloud/molecule/gcloud/tests/test_default.py
new file mode 100644
index 000000000..bb43defb5
--- /dev/null
+++ b/ansible_collections/google/cloud/molecule/gcloud/tests/test_default.py
@@ -0,0 +1,23 @@
+from __future__ import (absolute_import, division, print_function)
+import os
+import testinfra.utils.ansible_runner
+
+__metaclass__ = type
+
+testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
+ os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
+
+
+def test_service(host):
+ service = host.service('docker')
+
+ assert service.is_running
+ assert service.is_enabled
+
+
+def test_hosts_file(host):
+ f = host.file('/etc/hosts')
+
+ assert f.exists
+ assert f.user == 'root'
+ assert f.group == 'root'
diff --git a/ansible_collections/google/cloud/molecule/gcloud/verify.yml b/ansible_collections/google/cloud/molecule/gcloud/verify.yml
new file mode 100644
index 000000000..86afba4ff
--- /dev/null
+++ b/ansible_collections/google/cloud/molecule/gcloud/verify.yml
@@ -0,0 +1,9 @@
+---
+# This is an example playbook to execute Ansible tests.
+
+- name: Verify
+ hosts: all
+ tasks:
+ - name: Example assertion
+ ansible.builtin.assert:
+ that: true
diff --git a/ansible_collections/google/cloud/molecule/gcsfuse/Dockerfile.j2 b/ansible_collections/google/cloud/molecule/gcsfuse/Dockerfile.j2
new file mode 100644
index 000000000..5c2401ca8
--- /dev/null
+++ b/ansible_collections/google/cloud/molecule/gcsfuse/Dockerfile.j2
@@ -0,0 +1,111 @@
+# Molecule managed
+
+{% if item.registry is defined %}
+FROM {{ item.registry.url }}/{{ item.image }}
+{% else %}
+FROM {{ item.image }}
+{% endif %}
+ENV container=docker
+
+{# Initial Package Installs and Container Prep #}
+{% if item.image.split(':', 1)[0] in ["ubuntu"] %}
+RUN apt-get update \
+ && apt-get install -y --no-install-recommends \
+ locales software-properties-common rsyslog systemd systemd-cron sudo \
+ iproute2
+RUN sed -i 's/^\($ModLoad imklog\)/#\1/' /etc/rsyslog.conf
+{% elif item.image.split(':', 1)[0] in ["debian"] %}
+RUN apt-get update \
+ && apt-get install -y --no-install-recommends \
+ sudo systemd systemd-sysv \
+ build-essential wget
+{% elif item.image.split(':', 1)[0] in ["centos"] %}
+{% if item.image in ["centos:7"] %}
+RUN yum makecache fast && yum -y install deltarpm \
+{% elif item.image in ["centos:8"] %}
+RUN yum makecache --timer \
+{% endif %}
+ && yum -y install epel-release \
+ && yum -y update \
+ && yum -y install sudo which
+{% endif %}
+
+
+{# Install of Python2 #}
+{% if item.image in ["ubuntu:16.04"] %}
+RUN apt-get update \
+ && apt-get install -y --no-install-recommends python-setuptools wget \
+ && wget https://bootstrap.pypa.io/get-pip.py \
+ && python get-pip.py
+{% elif item.image in ["debian:9"] %}
+RUN apt-get update \
+ && apt-get install -y --no-install-recommends libffi-dev libssl-dev \
+ python-pip python-dev python-setuptools python-wheel
+{% elif item.image in ["centos:7"] %}
+RUN yum -y install python-pip
+{% endif %}
+
+{# Install of Python3 #}
+{% if item.image in ["ubuntu:18.04", "ubuntu:20.04", "debian:10"] %}
+RUN apt-get update \
+ && apt-get install -y --no-install-recommends \
+ apt-utils python3-setuptools python3-pip
+{% endif %}
+{% if item.image in ["centos:8"] %}
+RUN yum -y install hostname python3 python3-pip
+{% endif %}
+
+{# Steps for cleanup #}
+{% if item.image.split(':', 1)[0] in ["ubuntu", "debian"] %}
+RUN rm -Rf /var/lib/apt/lists/* \
+ && rm -Rf /usr/share/doc && rm -Rf /usr/share/man \
+ && apt-get clean
+{% elif item.image.split(':', 1)[0] in ["centos"] %}
+RUN yum clean all
+{% endif %}
+
+{# Steps for clenaup of systemd #}
+{% if item.image in ["centos:7", "centos:8", "debian:9"] %}
+RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \
+ systemd-tmpfiles-setup.service ] || rm -f $i; done); \
+ rm -f /lib/systemd/system/multi-user.target.wants/*;\
+ rm -f /etc/systemd/system/*.wants/*;\
+ rm -f /lib/systemd/system/local-fs.target.wants/*; \
+ rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
+ rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
+ rm -f /lib/systemd/system/basic.target.wants/*;\
+ rm -f /lib/systemd/system/anaconda.target.wants/*; \
+ mkdir -p /run/systemd/system
+{% endif %}
+{% if item.image in ["ubuntu:18.04", "ubuntu:20.04"] %}
+# Remove unnecessary getty and udev targets that result in high CPU usage when using
+# multiple containers with Molecule (https://github.com/ansible/molecule/issues/1104)
+RUN rm -f /lib/systemd/system/systemd*udev* \
+ && rm -f /lib/systemd/system/getty.target
+{% endif %}
+
+
+{% if item.image in ["centos:7", "centos:8"] %}
+# Disable requiretty.
+RUN sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers
+{% endif %}
+
+{% if item.image.split(':', 1)[0] not in ["centos", "debian"] %}
+# Fix potential UTF-8 errors with ansible-test.
+RUN locale-gen en_US.UTF-8
+{% endif %}
+
+# Install Ansible inventory file.
+RUN mkdir -p /etc/ansible
+RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts
+
+{% if item.image in ["centos:7", "centos:8", "debian:9", "debian:10"] %}
+VOLUME ["/sys/fs/cgroup"]
+{% elif item.image in ["ubuntu:16.04", "ubuntu:18.04", "ubuntu:20.04"] %}
+VOLUME ["/sys/fs/cgroup", "/tmp", "/run"]
+{% endif %}
+{% if item.image in ["centos:7", "centos:8"] %}
+CMD ["/usr/sbin/init"]
+{% elif item.image in ["ubuntu:16.04", "ubuntu:18.04", "ubuntu:20.04", "debian:9", "debian:10"] %}
+CMD ["/lib/systemd/systemd"]
+{% endif %}
diff --git a/ansible_collections/google/cloud/molecule/gcsfuse/converge.yml b/ansible_collections/google/cloud/molecule/gcsfuse/converge.yml
new file mode 100644
index 000000000..d24daf03b
--- /dev/null
+++ b/ansible_collections/google/cloud/molecule/gcsfuse/converge.yml
@@ -0,0 +1,14 @@
+---
+- name: Converge
+ hosts: all
+ pre_tasks:
+ - name: Update package cache
+ ansible.builtin.package:
+ update_cache: "yes"
+ changed_when: false
+ register: task_result
+ until: task_result is success
+ retries: 10
+ delay: 2
+ roles:
+ - role: google.cloud.gcsfuse
diff --git a/ansible_collections/google/cloud/molecule/gcsfuse/files/override.conf b/ansible_collections/google/cloud/molecule/gcsfuse/files/override.conf
new file mode 100644
index 000000000..76864e209
--- /dev/null
+++ b/ansible_collections/google/cloud/molecule/gcsfuse/files/override.conf
@@ -0,0 +1,2 @@
+[Service]
+ExecStartPre=
diff --git a/ansible_collections/google/cloud/molecule/gcsfuse/molecule.yml b/ansible_collections/google/cloud/molecule/gcsfuse/molecule.yml
new file mode 100644
index 000000000..7b7ab5473
--- /dev/null
+++ b/ansible_collections/google/cloud/molecule/gcsfuse/molecule.yml
@@ -0,0 +1,26 @@
+---
+dependency:
+ name: galaxy
+driver:
+ name: docker
+lint: |
+ set -e
+ yamllint .
+ ansible-lint
+platforms:
+ - name: instance
+ image: ubuntu:18.04
+ privileged: true
+ ansible.builtin.command: "/lib/systemd/systemd"
+ volumes:
+ - /sys/fs/cgroup:/sys/fs/cgroup:ro
+ - name: instance
+ image: debian:9
+ privileged: true
+ ansible.builtin.command: "/lib/systemd/systemd"
+ volumes:
+ - /sys/fs/cgroup:/sys/fs/cgroup:ro
+provisioner:
+ name: ansible
+ playbooks:
+ converge: ${MOLECULE_PLAYBOOK:-converge.yml}
diff --git a/ansible_collections/google/cloud/molecule/gcsfuse/tests/test_default.py b/ansible_collections/google/cloud/molecule/gcsfuse/tests/test_default.py
new file mode 100644
index 000000000..bb43defb5
--- /dev/null
+++ b/ansible_collections/google/cloud/molecule/gcsfuse/tests/test_default.py
@@ -0,0 +1,23 @@
+from __future__ import (absolute_import, division, print_function)
+import os
+import testinfra.utils.ansible_runner
+
+__metaclass__ = type
+
+testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
+ os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
+
+
+def test_service(host):
+ service = host.service('docker')
+
+ assert service.is_running
+ assert service.is_enabled
+
+
+def test_hosts_file(host):
+ f = host.file('/etc/hosts')
+
+ assert f.exists
+ assert f.user == 'root'
+ assert f.group == 'root'
diff --git a/ansible_collections/google/cloud/molecule/gcsfuse/verify.yml b/ansible_collections/google/cloud/molecule/gcsfuse/verify.yml
new file mode 100644
index 000000000..86afba4ff
--- /dev/null
+++ b/ansible_collections/google/cloud/molecule/gcsfuse/verify.yml
@@ -0,0 +1,9 @@
+---
+# This is an example playbook to execute Ansible tests.
+
+- name: Verify
+ hosts: all
+ tasks:
+ - name: Example assertion
+ ansible.builtin.assert:
+ that: true