From c6f13b250a88cf6f1392b96fb2be2e0611aae078 Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Mon, 17 May 2021 11:03:53 +0200 Subject: [PATCH 1/3] Make use of Github actions --- .ansible-lint | 3 ++ .github/workflows/ci.yml | 80 +++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 20 +++++++++ .travis.yml | 84 ----------------------------------- .yamllint | 15 +++++++ README.md | 3 +- Vagrantfile | 14 +++--- meta/main.yml | 1 - molecule/default/converge.yml | 9 ++++ molecule/default/molecule.yml | 19 ++++++++ molecule/default/prepare.yml | 5 +++ molecule/default/verify.yml | 5 +++ 12 files changed, 165 insertions(+), 93 deletions(-) create mode 100644 .ansible-lint create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml delete mode 100644 .travis.yml create mode 100644 .yamllint create mode 100644 molecule/default/converge.yml create mode 100644 molecule/default/molecule.yml create mode 100644 molecule/default/prepare.yml create mode 100644 molecule/default/verify.yml diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 0000000..148ddda --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,3 @@ +--- +warn_list: + - '106' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e8a0475 --- /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 ansible-lint[community,yamllint] + + - 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 14b2ddc..0000000 --- a/.travis.yml +++ /dev/null @@ -1,84 +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-get update -qq - - # Remove tinyproxy - - sudo apt-get remove --purge --yes tinyproxy - -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: "ALGQM2UJ5kp0REMH+H0NB99DZ55czLu0k4LPxxWM5GjSGma87HgkTgDiffQxMy1ZZNYXKg4MVvqvJgwmwAguOAA8zjVh/ubFjWAYr80tAOlozY13Q+7NcMy4HObEh/q82sIB845nfCdHWwf660XCjouIG4hOA0pyWwDH9pBGD0ksuHm/Eq6XOIxNb/UJNCUL9P/sWY1+cFbCL1ZusbENg3T0NAH6Gy5e6pDppWIzXfBMf0sKj2DMbfzaUo5FXFW9JQn7l+862vTQGj+5xySZW1j4kxnwSnT3E7hWfDLdWqUvxYpuqS51qJ92TolZlfWokq7nCJBW6oFB2bLa+B579vO/DdC1ycbfyO//ghxVQ5X+GaFAcD7O3QeSo86JYFsTjo8/IlGOixe52je2mV2nDwSnuVJVTRha73hKEoJ7RgOhh5UTXWzKHAvqoekQxpZOx7nIr02vtbwsww13P/CoCwGL/ZRN+d4ZGhlqYLask1HqUn/GhHwhHOBpTk4EiS0leXNlaL5mzuaVVKvokatPf4Rll/qi3l1wR5RoAO9JO+IKN0vebLxeAeY1kR2qQ3JxBEFxyqMJTiG6YrEkn5iiHdr+XgPEgPCS1qCQkpngoNVRszjjKP++gKMZNEsxc75c95S++4iT631U4nM60UIK9NLlux1u5ET6UC2AmPM7M/k=" 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/README.md b/README.md index 278bf22..662efa5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ ## tinyproxy -[![Build Status](https://travis-ci.org/Oefenweb/ansible-tinyproxy.svg?branch=master)](https://travis-ci.org/Oefenweb/ansible-tinyproxy) [![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-tinyproxy-blue.svg)](https://galaxy.ansible.com/Oefenweb/tinyproxy) +[![CI](https://github.com/Oefenweb/ansible-tinyproxy/workflows/CI/badge.svg)](https://github.com/Oefenweb/ansible-tinyproxy/actions?query=workflow%3ACI) +[![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-tinyproxy-blue.svg)](https://galaxy.ansible.com/Oefenweb/tinyproxy) Set up [tinyproxy](https://tinyproxy.github.io/) in Debian-like systems. diff --git a/Vagrantfile b/Vagrantfile index 0a0d24c..a0182a0 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -5,22 +5,22 @@ role = File.basename(File.expand_path(File.dirname(__FILE__))) boxes = [ { - :name => "ubuntu-1404", - :box => "bento/ubuntu-14.04", + :name => "ubuntu-1604", + :box => "bento/ubuntu-16.04", :ip => '10.0.0.12', :cpu => "50", :ram => "256" }, { - :name => "ubuntu-1604", - :box => "bento/ubuntu-16.04", + :name => "ubuntu-1804", + :box => "bento/ubuntu-18.04", :ip => '10.0.0.13', :cpu => "50", - :ram => "256" + :ram => "384" }, { - :name => "ubuntu-1804", - :box => "bento/ubuntu-18.04", + :name => "ubuntu-2004", + :box => "bento/ubuntu-20.04", :ip => '10.0.0.14', :cpu => "50", :ram => "384" diff --git a/meta/main.yml b/meta/main.yml index 05749d1..57cdcb2 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -11,7 +11,6 @@ galaxy_info: platforms: - name: Ubuntu versions: - - trusty - xenial - bionic - focal 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..9a6673d --- /dev/null +++ b/molecule/default/prepare.yml @@ -0,0 +1,5 @@ +--- +- name: Prepare + hosts: all + become: true + tasks: [] 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: [] From 69828d601a64d25c2f1f3824748c29dca6364a0c Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Mon, 17 May 2021 11:26:25 +0200 Subject: [PATCH 2/3] Fix failing tests --- molecule/default/prepare.yml | 6 +++++- molecule/default/verify.yml | 4 +++- tests/{ => tasks}/post.yml | 6 ++++-- tests/tasks/pre.yml | 14 ++++++++++++++ tests/test.yml | 29 +++-------------------------- tests/vagrant.yml | 5 +++-- 6 files changed, 32 insertions(+), 32 deletions(-) rename tests/{ => tasks}/post.yml (80%) create mode 100644 tests/tasks/pre.yml diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml index 9a6673d..bb63e11 100644 --- a/molecule/default/prepare.yml +++ b/molecule/default/prepare.yml @@ -2,4 +2,8 @@ - name: Prepare hosts: all become: true - tasks: [] + 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 index 44debad..edfe900 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -2,4 +2,6 @@ - name: Verify hosts: all become: true - tasks: [] + tasks: + - name: include tasks + include: "{{ playbook_dir }}/../../tests/tasks/post.yml" diff --git a/tests/post.yml b/tests/tasks/post.yml similarity index 80% rename from tests/post.yml rename to tests/tasks/post.yml index b3466d7..5a29868 100644 --- a/tests/post.yml +++ b/tests/tasks/post.yml @@ -1,6 +1,6 @@ # post test file --- -- name: post | install dependencies +- name: install test dependencies apt: name: - curl @@ -8,7 +8,7 @@ update_cache: true cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}" -- name: post | test installation +- name: test tinyproxy installation command: > curl -sL --head https://www.google.com --proxy http://127.0.0.1:3128 args: @@ -16,3 +16,5 @@ register: _result changed_when: false failed_when: _result.stdout.find('HTTP/1.0 200') == -1 + tags: + - skip_ansible_lint diff --git a/tests/tasks/pre.yml b/tests/tasks/pre.yml new file mode 100644 index 0000000..f7341eb --- /dev/null +++ b/tests/tasks/pre.yml @@ -0,0 +1,14 @@ +# post test file +--- +- name: install test dependencies + apt: + name: + - net-tools + - iproute2 + - ethtool + state: "{{ apt_install_state | default('latest') }}" + update_cache: true + cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}" + +- name: (re)gather facts + action: setup diff --git a/tests/test.yml b/tests/test.yml index 4e67ad7..3c9a06c 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -5,32 +5,9 @@ become: true pre_tasks: - name: include vars - include_vars: main.yml + include_vars: "{{ playbook_dir }}/vars/main.yml" roles: - ../../ post_tasks: - - include: post.yml - vars: - tinyproxy_tinyproxy_conf: - - | - User nobody - Group nogroup - Port {{ tinyproxy_port }} - Timeout 666 - DefaultErrorFile "/usr/share/tinyproxy/default.html" - StatFile "/usr/share/tinyproxy/stats.html" - Logfile "/var/log/tinyproxy/tinyproxy.log" - LogLevel Info - PidFile "/var/run/tinyproxy/tinyproxy.pid" - MaxClients 100 - MinSpareServers 5 - MaxSpareServers 20 - StartServers 10 - MaxRequestsPerChild 0 - {% for allow in tinyproxy_allow %} - Allow {{ allow }} - {% endfor %} - ViaProxyName "tinyproxy" - {% for connect_port in tinyproxy_connect_port %} - ConnectPort {{ connect_port }} - {% endfor %} + - name: include tasks + include: "{{ playbook_dir }}/tasks/post.yml" diff --git a/tests/vagrant.yml b/tests/vagrant.yml index 8b6646d..e3f8baf 100644 --- a/tests/vagrant.yml +++ b/tests/vagrant.yml @@ -5,8 +5,9 @@ become: true pre_tasks: - name: include vars - include_vars: main.yml + include_vars: "{{ playbook_dir }}/vars/main.yml" roles: - ../../ post_tasks: - - include: post.yml + - name: include tasks + include: "{{ playbook_dir }}/tasks/post.yml" From 7d1c295521b9b84e6158c9537fa7ef3f4f0001d3 Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Mon, 17 May 2021 11:30:23 +0200 Subject: [PATCH 3/3] More DRY --- molecule/default/verify.yml | 2 ++ tests/tasks/post.yml | 2 +- tests/test.yml | 2 ++ tests/vagrant.yml | 2 ++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index edfe900..d88340e 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -3,5 +3,7 @@ hosts: all become: true tasks: + - name: include vars + include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml" - name: include tasks include: "{{ playbook_dir }}/../../tests/tasks/post.yml" diff --git a/tests/tasks/post.yml b/tests/tasks/post.yml index 5a29868..3662d21 100644 --- a/tests/tasks/post.yml +++ b/tests/tasks/post.yml @@ -10,7 +10,7 @@ - name: test tinyproxy installation command: > - curl -sL --head https://www.google.com --proxy http://127.0.0.1:3128 + curl -sL --head https://www.google.com --proxy http://{{ ansible_lo['ipv4']['address'] }}:{{ tinyproxy_port }} args: warn: false register: _result diff --git a/tests/test.yml b/tests/test.yml index 3c9a06c..ca5ea5e 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -6,6 +6,8 @@ pre_tasks: - name: include vars include_vars: "{{ playbook_dir }}/vars/main.yml" + - name: include tasks + include: "{{ playbook_dir }}/tasks/pre.yml" roles: - ../../ post_tasks: diff --git a/tests/vagrant.yml b/tests/vagrant.yml index e3f8baf..3dfeb1c 100644 --- a/tests/vagrant.yml +++ b/tests/vagrant.yml @@ -6,6 +6,8 @@ pre_tasks: - name: include vars include_vars: "{{ playbook_dir }}/vars/main.yml" + - name: include tasks + include: "{{ playbook_dir }}/tasks/pre.yml" roles: - ../../ post_tasks: