diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c5bd6e1 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,80 @@ +--- +name: CI +'on': + pull_request: + push: + branches: + - master + schedule: + - cron: '30 1 * * 3' + +jobs: + + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Check out the codebase + uses: actions/checkout@v2 + + - name: Set up Python 3 + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install test dependencies + run: pip install yamllint ansible-lint + + - name: Lint code + run: | + yamllint . + ansible-lint + + molecule: + name: Molecule + runs-on: ubuntu-latest + defaults: + run: + working-directory: "${{ github.repository }}" + needs: + - lint + strategy: + fail-fast: false + matrix: + include: + - distro: debian8 + - distro: debian9 + - distro: debian10 + - distro: ubuntu1604 + ansible-version: '>=2.8, <2.9' + - distro: ubuntu1604 + ansible-version: '>=2.9, <2.10' + - distro: ubuntu1604 + ansible-version: '>=2.10, <2.11' + - distro: ubuntu1604 + - distro: ubuntu1804 + - distro: ubuntu2004 + + steps: + - name: Check out the codebase + uses: actions/checkout@v2 + with: + path: "${{ github.repository }}" + + - name: Set up Python 3 + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install test dependencies + run: pip install 'ansible${{ matrix.ansible-version }}' molecule[docker] docker + + - name: Run Molecule tests + run: | + molecule test + env: + ANSIBLE_FORCE_COLOR: '1' + ANSIBLE_VERBOSITY: '2' + MOLECULE_DEBUG: '1' + MOLECULE_DISTRO: "${{ matrix.distro }}" + PY_COLORS: '1' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..2354e68 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,20 @@ +--- +name: Release +'on': + push: + tags: + - '*' + +jobs: + + release: + name: Release + runs-on: ubuntu-latest + steps: + - name: Check out the codebase + uses: actions/checkout@v2 + + - name: Publish to Galaxy + uses: robertdebock/galaxy-action@1.1.0 + with: + galaxy_api_key: ${{ secrets.GALAXY_API_KEY }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 59dc183..0000000 --- a/.travis.yml +++ /dev/null @@ -1,85 +0,0 @@ ---- -sudo: required -dist: xenial - -language: python -python: - - "2.7" - - "3.5" - -env: - - ANSIBLE_VERSION=latest - - ANSIBLE_VERSION=2.10.2 - - ANSIBLE_VERSION=2.10.1 - - ANSIBLE_VERSION=2.10.0 - - ANSIBLE_VERSION=2.9.14 - - ANSIBLE_VERSION=2.9.13 - - ANSIBLE_VERSION=2.9.12 - - ANSIBLE_VERSION=2.9.11 - - ANSIBLE_VERSION=2.9.10 - - ANSIBLE_VERSION=2.9.9 - - ANSIBLE_VERSION=2.9.8 - - ANSIBLE_VERSION=2.9.7 - - ANSIBLE_VERSION=2.9.6 - - ANSIBLE_VERSION=2.9.5 - - ANSIBLE_VERSION=2.9.4 - - ANSIBLE_VERSION=2.9.3 - - ANSIBLE_VERSION=2.9.2 - - ANSIBLE_VERSION=2.9.1 - - ANSIBLE_VERSION=2.9.0 - - ANSIBLE_VERSION=2.8.16 - - ANSIBLE_VERSION=2.8.15 - - ANSIBLE_VERSION=2.8.14 - - ANSIBLE_VERSION=2.8.13 - - ANSIBLE_VERSION=2.8.12 - - ANSIBLE_VERSION=2.8.11 - - ANSIBLE_VERSION=2.8.10 - - ANSIBLE_VERSION=2.8.9 - - ANSIBLE_VERSION=2.8.8 - - ANSIBLE_VERSION=2.8.7 - - ANSIBLE_VERSION=2.8.6 - - ANSIBLE_VERSION=2.8.5 - - ANSIBLE_VERSION=2.8.4 - - ANSIBLE_VERSION=2.8.3 - - ANSIBLE_VERSION=2.8.2 - - ANSIBLE_VERSION=2.8.1 - - ANSIBLE_VERSION=2.8.0 - -branches: - only: - - master - -before_install: - - sudo apt-add-repository multiverse - - sudo apt-get update -qq - - # Remove snmp(d) - - sudo apt-get remove --purge --yes snmpd snmp snmp-mibs-downloader - -install: - # Install Ansible. - - if [ "$ANSIBLE_VERSION" = "latest" ]; then pip install ansible; else pip install ansible==$ANSIBLE_VERSION; fi - - if [ "$ANSIBLE_VERSION" = "latest" ]; then pip install ansible-lint; fi - -script: - # Check the role/playbook's syntax. - - ansible-playbook -i tests/inventory tests/test.yml --syntax-check - - # Run the role/playbook with ansible-playbook. - - ansible-playbook -i tests/inventory tests/test.yml -vvvv - - # Run the role/playbook again, checking to make sure it's idempotent. - - > - ansible-playbook -i tests/inventory tests/test.yml - | grep -q 'changed=0.*failed=0' - && (echo 'Idempotence test: pass' && exit 0) - || (echo 'Idempotence test: fail' && exit 1) - - - if [ "$ANSIBLE_VERSION" = "latest" ]; then ansible-lint tests/test.yml; fi - -notifications: - email: false - webhooks: https://galaxy.ansible.com/api/v1/notifications/ - slack: - rooms: - secure: "IclW1zxap49iXr81BbMMvl4eP68OArsB0badL1pY3eNeWb+BrrvQ/bs15jBQEtZnvTHPSKznXBv3IayNXa/j2WwtT+byrayDWMuvqBu5jjUc3RDFzCxS8LTVruukHBbP/lNT32BLzFHzLW3NuvrTWrmJS0Qe/VVt+UE3SfMCn7M=" diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..894450c --- /dev/null +++ b/.yamllint @@ -0,0 +1,15 @@ +--- +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + line-length: disable + truthy: disable + +ignore: | + .tox/ 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 4d16d1a..a0182a0 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -4,20 +4,6 @@ role = File.basename(File.expand_path(File.dirname(__FILE__))) boxes = [ - { - :name => "ubuntu-1204", - :box => "bento/ubuntu-12.04", - :ip => '10.0.0.10', - :cpu => "50", - :ram => "256" - }, - { - :name => "ubuntu-1404", - :box => "bento/ubuntu-14.04", - :ip => '10.0.0.11', - :cpu => "50", - :ram => "256" - }, { :name => "ubuntu-1604", :box => "bento/ubuntu-16.04", @@ -39,13 +25,6 @@ boxes = [ :cpu => "50", :ram => "384" }, - { - :name => "debian-7", - :box => "bento/debian-7", - :ip => '10.0.0.15', - :cpu => "50", - :ram => "256" - }, { :name => "debian-8", :box => "bento/debian-8", @@ -82,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/meta/main.yml b/meta/main.yml index e6fb79c..565a1a7 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -10,14 +10,11 @@ galaxy_info: platforms: - name: Ubuntu versions: - - precise - - trusty - xenial - bionic - focal - name: Debian versions: - - wheezy - jessie - stretch - buster diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml new file mode 100644 index 0000000..73043c4 --- /dev/null +++ b/molecule/default/converge.yml @@ -0,0 +1,9 @@ +--- +- name: Converge + hosts: all + become: true + pre_tasks: + - name: include vars + include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml" + roles: + - ../../../ diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..fbb7120 --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,19 @@ +--- +dependency: + name: galaxy +driver: + name: docker +platforms: + - name: instance + image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu1604}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true +provisioner: + name: ansible + playbooks: + prepare: prepare.yml + converge: converge.yml + verify: verify.yml diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml new file mode 100644 index 0000000..1600dec --- /dev/null +++ b/molecule/default/prepare.yml @@ -0,0 +1,9 @@ +--- +- name: Prepare + hosts: all + become: true + 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/molecule/default/verify.yml b/molecule/default/verify.yml new file mode 100644 index 0000000..44debad --- /dev/null +++ b/molecule/default/verify.yml @@ -0,0 +1,5 @@ +--- +- name: Verify + hosts: all + become: true + tasks: [] 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"