From cfeb9dbb727cf7b609fb15706109380b1ec0809a Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Tue, 12 Jan 2021 12:32:22 +0100 Subject: [PATCH] More DRY --- Dockerfile | 2 +- Vagrantfile | 5 ----- molecule/default/converge.yml | 6 +++--- molecule/default/prepare.yml | 18 +++++------------- tests/tasks/pre.yml | 14 ++++++++++++++ tests/test.yml | 8 +++++--- tests/vagrant.sh | 29 ----------------------------- tests/vagrant.yml | 3 +++ tests/vars/main.yml | 4 ++++ 9 files changed, 35 insertions(+), 54 deletions(-) create mode 100644 tests/tasks/pre.yml delete mode 100755 tests/vagrant.sh create mode 100644 tests/vars/main.yml diff --git a/Dockerfile b/Dockerfile index 6acedad..4f4cbb5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ RUN rm -rf $HOME/.cache # ansible RUN DEBIAN_FRONTEND=noninteractive apt-get install -y gcc libffi-dev libssl-dev net-tools iproute2 ethtool && \ apt-get clean -RUN pip install ansible==2.9.14 +RUN pip install ansible==2.9.15 RUN rm -rf $HOME/.cache # provision diff --git a/Vagrantfile b/Vagrantfile index e4a1e02..a0182a0 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -61,11 +61,6 @@ Vagrant.configure("2") do |config| vms.vm.network :private_network, ip: box[:ip] - # TODO: Cleanup - vms.vm.provision :shell do |shell| - shell.path = "tests/vagrant.sh" - end - vms.vm.provision :ansible do |ansible| ansible.playbook = "tests/vagrant.yml" ansible.verbose = "vv" diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index 4cab4ea..73043c4 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -2,8 +2,8 @@ - name: Converge hosts: all become: true + pre_tasks: + - name: include vars + include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml" roles: - ../../../ - vars: - snmpd_agent_address: - - "udp:{{ ansible_lo['ipv4']['address'] }}:10161" diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml index dced4ae..1600dec 100644 --- a/molecule/default/prepare.yml +++ b/molecule/default/prepare.yml @@ -2,16 +2,8 @@ - name: Prepare hosts: all become: true - tasks: - - name: Enable non-free - apt_repository: - repo: "{{ item.type }} {{ item.url }} {{ item.component }}" - filename: non-free - with_items: - - type: deb - url: "http://ftp.nl.debian.org/debian/ {{ ansible_distribution_release }}" - component: contrib non-free - - type: deb-src - url: "http://ftp.nl.debian.org/debian/ {{ ansible_distribution_release }}" - component: contrib non-free - when: ansible_distribution == 'Debian' + pre_tasks: + - name: include vars + include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml" + - name: include tasks + include: "{{ playbook_dir }}/../../tests/tasks/pre.yml" diff --git a/tests/tasks/pre.yml b/tests/tasks/pre.yml new file mode 100644 index 0000000..96b540c --- /dev/null +++ b/tests/tasks/pre.yml @@ -0,0 +1,14 @@ +# pre test file for snmpd +--- +- name: enable non-free + apt_repository: + repo: "{{ item.type }} {{ item.url }} {{ item.component }}" + filename: non-free + with_items: + - type: deb + url: "http://ftp.nl.debian.org/debian/ {{ ansible_distribution_release }}" + component: contrib non-free + - type: deb-src + url: "http://ftp.nl.debian.org/debian/ {{ ansible_distribution_release }}" + component: contrib non-free + when: ansible_distribution == 'Debian' diff --git a/tests/test.yml b/tests/test.yml index 941fde2..0062d99 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -3,8 +3,10 @@ - hosts: localhost connection: local become: true + pre_tasks: + - name: include vars + include_vars: "{{ playbook_dir }}/vars/main.yml" + - name: include tasks + include: "{{ playbook_dir }}/tasks/pre.yml" roles: - ../../ - vars: - snmpd_agent_address: - - "udp:{{ ansible_lo['ipv4']['address'] }}:10161" diff --git a/tests/vagrant.sh b/tests/vagrant.sh deleted file mode 100755 index 16996f0..0000000 --- a/tests/vagrant.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash -# -# set -x; -set -e; -set -o pipefail; -# -thisFile="$(readlink -f ${0})"; -thisFilePath="$(dirname ${thisFile})"; - -# Only provision once -if [[ -f /provisioned ]]; then - exit 0; -fi - -export DEBIAN_FRONTEND=noninteractive; - -shopt -s expand_aliases; -alias apt-update='apt-get update -qq'; -alias apt-install='apt-get install -q -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"'; - -# Enable non-free repository in Debian -if lsb_release -id | grep -q Debian; then - codename="$(lsb_release -c | awk '{ print $2 }')"; - - echo "deb http://ftp.nl.debian.org/debian/ ${codename} contrib non-free" > /etc/apt/sources.list.d/non-free.list; - echo "deb-src http://ftp.nl.debian.org/debian/ ${codename} contrib non-free" >> /etc/apt/sources.list.d/non-free.list; -fi - -touch /provisioned; diff --git a/tests/vagrant.yml b/tests/vagrant.yml index edab59a..be85a83 100644 --- a/tests/vagrant.yml +++ b/tests/vagrant.yml @@ -3,5 +3,8 @@ - hosts: all remote_user: vagrant become: true + pre_tasks: + - name: include tasks + include: "{{ playbook_dir }}/tasks/pre.yml" roles: - ../../ diff --git a/tests/vars/main.yml b/tests/vars/main.yml new file mode 100644 index 0000000..53d74ba --- /dev/null +++ b/tests/vars/main.yml @@ -0,0 +1,4 @@ +# vars file for snmpd +--- +snmpd_agent_address: + - "udp:{{ ansible_lo['ipv4']['address'] }}:10161"