From b49b212bdee62c328d64a1cbf310b086218ec7da Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Thu, 4 Feb 2021 15:04:31 +0100 Subject: [PATCH 1/5] Make use of github actions --- .ansible-lint | 5 +- .github/workflows/ci.yml | 80 +++++++++++++++++++++++++++++++ .github/workflows/release.yml | 20 ++++++++ .travis.yml | 90 ----------------------------------- .yamllint | 15 ++++++ Dockerfile | 4 +- README.md | 2 +- Vagrantfile | 21 +++----- meta/main.yml | 3 +- molecule/default/converge.yml | 6 +++ molecule/default/molecule.yml | 19 ++++++++ molecule/default/prepare.yml | 9 ++++ molecule/default/verify.yml | 5 ++ tasks/configure.yml | 1 + tasks/main.yml | 2 +- tests/pre.yml | 16 ------- tests/tasks/pre.yml | 34 +++++++++++++ tests/test.yml | 13 ++--- tests/vagrant.yml | 5 ++ tests/vars/main.yml | 9 ++++ 20 files changed, 221 insertions(+), 138 deletions(-) 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 delete mode 100644 tests/pre.yml create mode 100644 tests/tasks/pre.yml create mode 100644 tests/vars/main.yml diff --git a/.ansible-lint b/.ansible-lint index cda5365..c099c60 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -1,3 +1,2 @@ -skip_list: - - '204' - - '405' +warn_list: + - '106' 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 4b3d1c9..0000000 --- a/.travis.yml +++ /dev/null @@ -1,90 +0,0 @@ ---- -sudo: required -dist: xenial - -language: python -python: - - "2.7" - - "3.5" - -services: - - mysql - -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 autossh - - sudo apt-get remove --purge --yes autossh - - # Generate ssh key - - ssh-keygen -t rsa -b 2048 -C '' -P '' -f files/id_rsa -q - -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: "CYFt1L9kLZpch/oOAcvaYQDvX1upTdEhmpGutialz/L4gnn0DFhFomyfqA0quwZFnBIwwuohsQt3OkPW2UGXZOR6nLo3/hRu0mNvQmhcjcoqzgkhfezHwhd2QKsWEppthjDwGBbHAGYWOeT076uWOyq+LbMuOrD67ivwc/fYS11E+mJ3nOoSdylhy4/4Moy3oBy/Qs0ZVhj75Jsug+Va20qbZqoO6WsEltVP16Kw0GXF0DVT3w4BoMhgUn7bJHtFm+kCOgLL350i5F7kAE0b+wU6uFIT/ZaNLlFwvTaPU0O/pOj6WiCv889OCT/zIs+P4w5SxCZYw6Ih0gaxJC7y8W55tmO+eAedMTsVZ7xOIpu9vIVvHhfHhJVAB1JJUny6PBI4gasSjLbgr6fzzgJ+dDp9PAafnYR7NsyF3YrVuQmYpCxxuLNMZndJO5VwXBNbUCWmPGViwio9JKpjZ2hEOmA9hH8b5m6MfZd0vXbIgua5Y3p08btjpnSrePSYpTDiiummiJmmpg7W8u9pZz4YHSIOI/2wVl7ulDMR8kSX2TrYMKDaCv6AZSC0+GwgFJxHiQageJ8akJiEBODdMAEQaUUSoGTLl+Io59C0SbPSSerWIEQ7GwM+xiEsU65rvlBAGaEO0PPo+PZ9BKv9iH0YUMRGH5rXGzvIXK7aXTWYtkw=" 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 78650c6..4f4cbb5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,9 +9,9 @@ RUN curl -sL https://bootstrap.pypa.io/get-pip.py | python - RUN rm -rf $HOME/.cache # ansible -RUN DEBIAN_FRONTEND=noninteractive apt-get install -y gcc libffi-dev libssl-dev && \ +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/README.md b/README.md index 445c142..bff6dcf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## autossh-tunnel-client -[![Build Status](https://travis-ci.org/Oefenweb/ansible-autossh-tunnel-client.svg?branch=master)](https://travis-ci.org/Oefenweb/ansible-autossh-tunnel-client) +[![CI](https://github.com/Oefenweb/ansible-autossh-tunnel-client/workflows/CI/badge.svg)](https://github.com/Oefenweb/ansible-autossh-tunnel-client/actions?query=workflow%3ACI) [![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-autossh--tunnel--client-blue.svg)](https://galaxy.ansible.com/Oefenweb/autossh-tunnel-client) Set up a persistent tunnel (using `autossh`) in Ubuntu systems (client side). diff --git a/Vagrantfile b/Vagrantfile index 05a5ee6..8868feb 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -5,29 +5,22 @@ role = File.basename(File.expand_path(File.dirname(__FILE__))) boxes = [ { - :name => "ubuntu-1204", - :box => "bento/ubuntu-12.04", - :ip => '10.0.0.11', - :cpu => "50", - :ram => "256" - }, - { - :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 f2a9200..98af2fd 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -10,10 +10,9 @@ galaxy_info: platforms: - name: Ubuntu versions: - - precise - - trusty - xenial - bionic + - focal galaxy_tags: - system - networking diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml new file mode 100644 index 0000000..be762b2 --- /dev/null +++ b/molecule/default/converge.yml @@ -0,0 +1,6 @@ +--- +- name: Converge + hosts: all + become: true + 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/tasks/configure.yml b/tasks/configure.yml index 47a70a9..d361d00 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -37,6 +37,7 @@ - name: configure | copy key file(s) copy: src: "{{ item.src }}" + remote_src: "{{ item.remote_src | default(false) }}" dest: "{{ autossh_tunnel_client_configuration_directory }}/{{ item.dest | default(item.src | basename) }}" owner: "{{ item.owner | default('root') }}" group: "{{ item.group | default(item.owner) | default('root') }}" diff --git a/tasks/main.yml b/tasks/main.yml index a16f833..7f2a146 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -2,7 +2,7 @@ --- - name: facts | set set_fact: - is_docker_guest: "{{ ansible_virtualization_role | default('host') == 'guest' and ansible_virtualization_type | default('none') == 'docker' }}" + is_docker_guest: "{{ ansible_virtualization_role | default('host') == 'guest' and ansible_virtualization_type | default('none') == 'docker' }}" tags: - configuration - autossh-tunnel-client diff --git a/tests/pre.yml b/tests/pre.yml deleted file mode 100644 index 6635665..0000000 --- a/tests/pre.yml +++ /dev/null @@ -1,16 +0,0 @@ -# pre test file for autossh-tunnel-client ---- -- name: pre | install dependencies - apt: - name: - - openssh-client - state: "{{ apt_install_state | default('latest') }}" - update_cache: true - cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}" - -- name: pre | generate key pair - command: > - ssh-keygen -t rsa -b 2048 -C '' -P '' -f {{ playbook_dir }}/../files/id_rsa -q - args: - creates: "{{ playbook_dir }}/../files/id_rsa" - become: false diff --git a/tests/tasks/pre.yml b/tests/tasks/pre.yml new file mode 100644 index 0000000..3219795 --- /dev/null +++ b/tests/tasks/pre.yml @@ -0,0 +1,34 @@ +# pre test file for autossh-tunnel-client +--- +- name: install dependencies + apt: + name: + - openssh-client + state: "{{ apt_install_state | default('latest') }}" + update_cache: true + cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}" + +- name: add ssh directory + command: > + mkdir -p ~{{ ansible_user_id }}/.ssh + args: + creates: "~{{ ansible_user_id }}/.ssh" + +- name: generate key pair + command: > + ssh-keygen -t rsa -b 2048 -C '' -P '' -f ~{{ ansible_user_id }}/.ssh/id_rsa -q + args: + creates: "~{{ ansible_user_id }}/.ssh/id_rsa" + +- name: add public key + shell: > + cat ~{{ ansible_user_id }}/.ssh/id_rsa.pub > ~{{ ansible_user_id }}/.ssh/authorized_keys + args: + creates: "~{{ ansible_user_id }}/.ssh/authorized_keys" + +- name: install test service + apt: + name: + - openssh-server + - memcached + state: "{{ apt_install_state | default('latest') }}" diff --git a/tests/test.yml b/tests/test.yml index 3bb4dcf..3e7818b 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -4,14 +4,9 @@ connection: local become: true pre_tasks: - - include: pre.yml + - name: include vars + include_vars: "{{ playbook_dir }}/vars/main.yml" + - name: include tasks + include: "{{ playbook_dir }}/tasks/pre.yml" roles: - ../../ - vars: - autossh_tunnel_client_key_map: - - src: id_rsa - owner: "{{ ansible_user_id }}" - autossh_tunnel_client_host: localhost - autossh_tunnel_client_user: travis - autossh_tunnel_client_forward: - - '3307:127.0.0.1:3306' diff --git a/tests/vagrant.yml b/tests/vagrant.yml index 1950bf6..6038212 100644 --- a/tests/vagrant.yml +++ b/tests/vagrant.yml @@ -3,5 +3,10 @@ - hosts: all remote_user: vagrant become: true + pre_tasks: + - name: include vars + include_vars: "{{ playbook_dir }}/vars/main.yml" + - 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..652711d --- /dev/null +++ b/tests/vars/main.yml @@ -0,0 +1,9 @@ +# vars file for autossh-tunnel-client +--- +autossh_tunnel_client_key_map: + - src: "~{{ ansible_user_id }}/.ssh/id_rsa" + remote_src: true +autossh_tunnel_client_host: localhost +autossh_tunnel_client_user: "{{ ansible_user_id }}" +autossh_tunnel_client_forward: + - '11212:127.0.0.1:11211' From ea3ae702c20fb6a666c4445cc9786d36a04c2694 Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Thu, 4 Feb 2021 15:14:58 +0100 Subject: [PATCH 2/5] Fixes --- tests/tasks/post.yml | 18 ++++++++++++++++++ tests/vagrant.yml | 3 +++ tests/vars/main.yml | 3 ++- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/tasks/post.yml diff --git a/tests/tasks/post.yml b/tests/tasks/post.yml new file mode 100644 index 0000000..8a2e816 --- /dev/null +++ b/tests/tasks/post.yml @@ -0,0 +1,18 @@ +# pre test file for autossh-tunnel-client +--- +- name: install dependencies + apt: + name: + - netcat-traditional + state: "{{ apt_install_state | default('latest') }}" + update_cache: true + cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}" + +- name: add public key + shell: > + echo stats | nc {{ ansible_lo['ipv4']['address'] }} {{ autossh_tunnel_client_tunneled_memcached_port }} + | grep -q 'STAT' + && (echo 'Availability test: pass' && exit 0) + || (echo 'Availability test: fail' && exit 1) + args: + creates: "~{{ ansible_user_id }}/.ssh/authorized_keys" diff --git a/tests/vagrant.yml b/tests/vagrant.yml index 6038212..a5693c2 100644 --- a/tests/vagrant.yml +++ b/tests/vagrant.yml @@ -10,3 +10,6 @@ include: "{{ playbook_dir }}/tasks/pre.yml" roles: - ../../ + post_tasks: + - name: include tasks + include: "{{ playbook_dir }}/tasks/post.yml" diff --git a/tests/vars/main.yml b/tests/vars/main.yml index 652711d..e63d552 100644 --- a/tests/vars/main.yml +++ b/tests/vars/main.yml @@ -5,5 +5,6 @@ autossh_tunnel_client_key_map: remote_src: true autossh_tunnel_client_host: localhost autossh_tunnel_client_user: "{{ ansible_user_id }}" +autossh_tunnel_client_tunneled_memcached_port: 11212 autossh_tunnel_client_forward: - - '11212:127.0.0.1:11211' + - "{{ _autossh_tunnel_client_tunneled_memcached_port }}:{{ ansible_lo['ipv4']['address'] }}:11211" From b2ccf590d3012762d3b2241bca0b9a064f2ae3fc Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Thu, 4 Feb 2021 15:19:30 +0100 Subject: [PATCH 3/5] Fixes --- molecule/default/converge.yml | 3 +++ molecule/default/verify.yml | 6 ++++++ tests/tasks/post.yml | 5 ++--- tests/test.yml | 3 +++ tests/vars/main.yml | 4 ++-- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index be762b2..73043c4 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -2,5 +2,8 @@ - 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/verify.yml b/molecule/default/verify.yml index 44debad..3a50d4d 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -2,4 +2,10 @@ - name: Verify hosts: all become: true +# pre_tasks: +# - name: include vars +# include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml" tasks: [] +# post_tasks: +# - name: include tasks +# include: "{{ playbook_dir }}/../../tests/tasks/post.yml" diff --git a/tests/tasks/post.yml b/tests/tasks/post.yml index 8a2e816..ab5b19e 100644 --- a/tests/tasks/post.yml +++ b/tests/tasks/post.yml @@ -8,11 +8,10 @@ update_cache: true cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}" -- name: add public key +- name: check tunneled service shell: > echo stats | nc {{ ansible_lo['ipv4']['address'] }} {{ autossh_tunnel_client_tunneled_memcached_port }} | grep -q 'STAT' && (echo 'Availability test: pass' && exit 0) || (echo 'Availability test: fail' && exit 1) - args: - creates: "~{{ ansible_user_id }}/.ssh/authorized_keys" + changed_when: false diff --git a/tests/test.yml b/tests/test.yml index 3e7818b..5265e06 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -10,3 +10,6 @@ include: "{{ playbook_dir }}/tasks/pre.yml" roles: - ../../ +# post_tasks: +# - name: include tasks +# include: "{{ playbook_dir }}/tasks/post.yml" diff --git a/tests/vars/main.yml b/tests/vars/main.yml index e63d552..875b3f3 100644 --- a/tests/vars/main.yml +++ b/tests/vars/main.yml @@ -3,8 +3,8 @@ autossh_tunnel_client_key_map: - src: "~{{ ansible_user_id }}/.ssh/id_rsa" remote_src: true -autossh_tunnel_client_host: localhost +autossh_tunnel_client_host: "{{ ansible_lo['ipv4']['address'] }}" autossh_tunnel_client_user: "{{ ansible_user_id }}" autossh_tunnel_client_tunneled_memcached_port: 11212 autossh_tunnel_client_forward: - - "{{ _autossh_tunnel_client_tunneled_memcached_port }}:{{ ansible_lo['ipv4']['address'] }}:11211" + - "{{ autossh_tunnel_client_tunneled_memcached_port }}:{{ ansible_lo['ipv4']['address'] }}:11211" From 11903596caaaec7f782319dcdb0223fb808cfb2d Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Thu, 4 Feb 2021 16:37:21 +0100 Subject: [PATCH 4/5] Cleanup --- tests/tasks/pre.yml | 18 ++++++++++-------- tests/vars/main.yml | 9 +++++++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/tests/tasks/pre.yml b/tests/tasks/pre.yml index 3219795..9c952a9 100644 --- a/tests/tasks/pre.yml +++ b/tests/tasks/pre.yml @@ -9,22 +9,24 @@ cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}" - name: add ssh directory - command: > - mkdir -p ~{{ ansible_user_id }}/.ssh - args: - creates: "~{{ ansible_user_id }}/.ssh" + file: + path: "{{ autossh_tunnel_client_ssh_directory }}" + state: directory + owner: root + group: root + mode: 0700 - name: generate key pair command: > - ssh-keygen -t rsa -b 2048 -C '' -P '' -f ~{{ ansible_user_id }}/.ssh/id_rsa -q + ssh-keygen -t rsa -b 2048 -C '' -P '' -f {{ autossh_tunnel_client_private_key_file }} -q args: - creates: "~{{ ansible_user_id }}/.ssh/id_rsa" + creates: "{{ autossh_tunnel_client_private_key_file }}" - name: add public key shell: > - cat ~{{ ansible_user_id }}/.ssh/id_rsa.pub > ~{{ ansible_user_id }}/.ssh/authorized_keys + cat {{ autossh_tunnel_client_public_key_file }} > {{ autossh_tunnel_client_authorized_keys_file }} args: - creates: "~{{ ansible_user_id }}/.ssh/authorized_keys" + creates: "{{ autossh_tunnel_client_authorized_keys_file }}" - name: install test service apt: diff --git a/tests/vars/main.yml b/tests/vars/main.yml index 875b3f3..0153319 100644 --- a/tests/vars/main.yml +++ b/tests/vars/main.yml @@ -1,10 +1,15 @@ # vars file for autossh-tunnel-client --- autossh_tunnel_client_key_map: - - src: "~{{ ansible_user_id }}/.ssh/id_rsa" + - src: "{{ autossh_tunnel_client_private_key_file }}" remote_src: true autossh_tunnel_client_host: "{{ ansible_lo['ipv4']['address'] }}" autossh_tunnel_client_user: "{{ ansible_user_id }}" -autossh_tunnel_client_tunneled_memcached_port: 11212 autossh_tunnel_client_forward: - "{{ autossh_tunnel_client_tunneled_memcached_port }}:{{ ansible_lo['ipv4']['address'] }}:11211" + +autossh_tunnel_client_ssh_directory: "~{{ ansible_user_id }}/.ssh" +autossh_tunnel_client_private_key_file: "{{ autossh_tunnel_client_ssh_directory }}/id_rsa" +autossh_tunnel_client_public_key_file: "{{ autossh_tunnel_client_private_key_file }}.pub" +autossh_tunnel_client_authorized_keys_file: "{{ autossh_tunnel_client_ssh_directory }}/authorized_keys" +autossh_tunnel_client_tunneled_memcached_port: 11212 From 6300fa9b561af37d348011d51ed483b7c6a8ec8a Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Thu, 4 Feb 2021 17:03:38 +0100 Subject: [PATCH 5/5] Omit remote_src if not specified --- tasks/configure.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/configure.yml b/tasks/configure.yml index d361d00..8810b71 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -37,7 +37,7 @@ - name: configure | copy key file(s) copy: src: "{{ item.src }}" - remote_src: "{{ item.remote_src | default(false) }}" + remote_src: "{{ item.remote_src | default(omit) }}" dest: "{{ autossh_tunnel_client_configuration_directory }}/{{ item.dest | default(item.src | basename) }}" owner: "{{ item.owner | default('root') }}" group: "{{ item.group | default(item.owner) | default('root') }}"