From 627bdd6e6ebab26e7a103492ad4dcde5ebe0204d Mon Sep 17 00:00:00 2001 From: Steve Smith Date: Tue, 9 Apr 2019 15:15:42 +1000 Subject: [PATCH] New task for common package installs that is cross-distro. --- roles/linux-common/.yamllint | 11 ++++++++++ .../molecule/default/Dockerfile.j2 | 14 +++++++++++++ .../molecule/default/molecule.yml | 20 +++++++++++++++++++ .../molecule/default/playbook.yml | 5 +++++ .../molecule/default/tests/test_default.py | 16 +++++++++++++++ roles/linux-common/tasks/debian.yml | 1 + roles/linux-common/tasks/main.yml | 12 +++++++++++ roles/linux-common/tasks/redhat.yml | 6 ++++++ 8 files changed, 85 insertions(+) create mode 100644 roles/linux-common/.yamllint create mode 100644 roles/linux-common/molecule/default/Dockerfile.j2 create mode 100644 roles/linux-common/molecule/default/molecule.yml create mode 100644 roles/linux-common/molecule/default/playbook.yml create mode 100644 roles/linux-common/molecule/default/tests/test_default.py create mode 100644 roles/linux-common/tasks/debian.yml create mode 100644 roles/linux-common/tasks/main.yml create mode 100644 roles/linux-common/tasks/redhat.yml diff --git a/roles/linux-common/.yamllint b/roles/linux-common/.yamllint new file mode 100644 index 0000000..ad0be76 --- /dev/null +++ b/roles/linux-common/.yamllint @@ -0,0 +1,11 @@ +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + line-length: disable + truthy: disable diff --git a/roles/linux-common/molecule/default/Dockerfile.j2 b/roles/linux-common/molecule/default/Dockerfile.j2 new file mode 100644 index 0000000..e6aa95d --- /dev/null +++ b/roles/linux-common/molecule/default/Dockerfile.j2 @@ -0,0 +1,14 @@ +# Molecule managed + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +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; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-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; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi diff --git a/roles/linux-common/molecule/default/molecule.yml b/roles/linux-common/molecule/default/molecule.yml new file mode 100644 index 0000000..c6a6d26 --- /dev/null +++ b/roles/linux-common/molecule/default/molecule.yml @@ -0,0 +1,20 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint +platforms: + - name: amazon_linux2 + image: amazonlinux:2 + - name: ubuntu_lts + image: ubuntu:bionic +provisioner: + name: ansible + lint: + name: ansible-lint +verifier: + name: testinfra + lint: + name: flake8 diff --git a/roles/linux-common/molecule/default/playbook.yml b/roles/linux-common/molecule/default/playbook.yml new file mode 100644 index 0000000..33ddb66 --- /dev/null +++ b/roles/linux-common/molecule/default/playbook.yml @@ -0,0 +1,5 @@ +--- +- name: Converge + hosts: all + roles: + - role: linux-common diff --git a/roles/linux-common/molecule/default/tests/test_default.py b/roles/linux-common/molecule/default/tests/test_default.py new file mode 100644 index 0000000..123aa3c --- /dev/null +++ b/roles/linux-common/molecule/default/tests/test_default.py @@ -0,0 +1,16 @@ +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_user_prereq(host): + f = host.file('/usr/sbin/useradd') + assert f.exists + + +def test_support_packages(host): + assert host.file('/usr/bin/jq').exists + assert host.file('/usr/bin/curl').exists diff --git a/roles/linux-common/tasks/debian.yml b/roles/linux-common/tasks/debian.yml new file mode 100644 index 0000000..ed97d53 --- /dev/null +++ b/roles/linux-common/tasks/debian.yml @@ -0,0 +1 @@ +--- diff --git a/roles/linux-common/tasks/main.yml b/roles/linux-common/tasks/main.yml new file mode 100644 index 0000000..7cc3138 --- /dev/null +++ b/roles/linux-common/tasks/main.yml @@ -0,0 +1,12 @@ +--- + +# Note: Try and limit these to packages that are distro-specific, and +# place commonly-named ones below. +- name: Install distro-specific prerequisites + include: "{{ ansible_os_family|lower }}.yml" + +- name: Install common support packags + package: + name: + - jq + - curl diff --git a/roles/linux-common/tasks/redhat.yml b/roles/linux-common/tasks/redhat.yml new file mode 100644 index 0000000..d507be5 --- /dev/null +++ b/roles/linux-common/tasks/redhat.yml @@ -0,0 +1,6 @@ +--- + +- name: Install Redhat family support packages + yum: + name: + - shadow-utils