diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7c00f3c..5e5c0cf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,9 @@ jobs: python-version: '3.x' - name: Install test dependencies - run: pip install ansible-lint[community,yamllint] + run: | + pip install ansible-lint + ansible-galaxy install -r requirements.yml - name: Lint code run: | @@ -43,11 +45,8 @@ jobs: matrix: include: - distro: debian8 - ansible-version: '<2.10' - distro: debian9 - distro: debian10 - - distro: ubuntu1604 - ansible-version: '>=2.9, <2.10' - distro: ubuntu1604 ansible-version: '>=2.10, <2.11' - distro: ubuntu1604 diff --git a/Dockerfile b/Dockerfile index c7cdf41..6ebe0c4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,20 @@ -FROM ubuntu:16.04 +FROM ubuntu:18.04 MAINTAINER Mischa ter Smitten +ENV LANG C.UTF-8 +ENV LC_ALL C.UTF-8 + # python RUN apt-get update && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y python-minimal python-dev curl && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y python3-minimal python3-dev curl && \ apt-get clean -RUN curl -sL https://bootstrap.pypa.io/pip/2.7/get-pip.py | python - +RUN curl -sL https://bootstrap.pypa.io/pip/3.6/get-pip.py | python3 - RUN rm -rf $HOME/.cache # ansible -RUN DEBIAN_FRONTEND=noninteractive apt-get install -y gcc libffi-dev libssl-dev net-tools iproute2 ethtool && \ +RUN DEBIAN_FRONTEND=noninteractive apt-get install -y python3-apt && \ apt-get clean -RUN pip install ansible==2.9.15 +RUN pip3 install ansible==2.10.7 RUN rm -rf $HOME/.cache # provision diff --git a/handlers/main.yml b/handlers/main.yml index 19da4f0..e28ba49 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,7 +1,7 @@ # handlers file --- - name: restart autossh-tunnel-client - service: + ansible.builtin.service: name: autossh-tunnel-client state: restarted when: service_default_state | default('started') == 'started' diff --git a/meta/main.yml b/meta/main.yml index 450fb7d..13760e0 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,13 +1,12 @@ # meta file --- galaxy_info: - namespace: oefenweb + author: oefenweb role_name: autossh_tunnel_client - author: Mischa ter Smitten company: Oefenweb.nl B.V. description: Set up a persistent tunnel (using autossh) in Ubuntu systems (client side) license: MIT - min_ansible_version: 2.9.0 + min_ansible_version: 2.10.0 platforms: - name: Ubuntu versions: diff --git a/molecule/default/collections.yml b/molecule/default/collections.yml new file mode 100644 index 0000000..c3d7e2a --- /dev/null +++ b/molecule/default/collections.yml @@ -0,0 +1,6 @@ +--- +collections: + - name: community.docker + version: '>=1.2.0,<2' + - name: community.general + version: '>=2,<3' diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index 73043c4..8596f09 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -4,6 +4,6 @@ become: true pre_tasks: - name: include vars - include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml" + ansible.builtin.include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml" roles: - ../../../ diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml index 1600dec..e718055 100644 --- a/molecule/default/prepare.yml +++ b/molecule/default/prepare.yml @@ -4,6 +4,6 @@ become: true pre_tasks: - name: include vars - include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml" + ansible.builtin.include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml" - name: include tasks - include: "{{ playbook_dir }}/../../tests/tasks/pre.yml" + ansible.builtin.include: "{{ playbook_dir }}/../../tests/tasks/pre.yml" diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index 3a50d4d..e548de0 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -2,10 +2,10 @@ - name: Verify hosts: all become: true -# pre_tasks: -# - name: include vars -# include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml" + # pre_tasks: + # - name: include vars + # ansible.builtin.include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml" tasks: [] -# post_tasks: -# - name: include tasks -# include: "{{ playbook_dir }}/../../tests/tasks/post.yml" + # post_tasks: + # - name: include tasks + # ansible.builtin.include: "{{ playbook_dir }}/../../tests/tasks/post.yml" diff --git a/requirements.yml b/requirements.yml new file mode 100644 index 0000000..3d5f1cd --- /dev/null +++ b/requirements.yml @@ -0,0 +1,3 @@ +# requirements file +--- +collections: [] diff --git a/tasks/configure.yml b/tasks/configure.yml index 08e6e17..4125a86 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -1,7 +1,7 @@ # tasks file --- - name: configure | create directories - file: + ansible.builtin.file: path: "{{ item.dest }}" state: directory owner: root @@ -17,7 +17,7 @@ - autossh-tunnel-client-configure-directories-create - name: configure | update configuration file(s) - template: + ansible.builtin.template: src: "{{ item.src }}" dest: "{{ item.dest }}" owner: root @@ -35,7 +35,7 @@ - autossh-tunnel-client-configure-configuration - name: configure | copy key file(s) - copy: + ansible.builtin.copy: src: "{{ item.src }}" remote_src: "{{ item.remote_src | default(omit) }}" dest: "{{ autossh_tunnel_client_configuration_directory }}/{{ item.dest | default(item.src | basename) }}" diff --git a/tasks/main.yml b/tasks/main.yml index e8a69ba..4d2b026 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,7 +1,7 @@ # tasks file --- - name: facts | set - set_fact: + ansible.builtin.set_fact: is_docker_guest: "{{ ansible_virtualization_role | default('host') == 'guest' and ansible_virtualization_type | default('none') == 'docker' }}" tags: - configuration @@ -9,7 +9,7 @@ - autossh-tunnel-client-facts - name: install package - apt: + ansible.builtin.apt: name: "{{ autossh_tunnel_client_dependencies }}" state: "{{ apt_install_state | default('latest') }}" update_cache: true @@ -19,14 +19,15 @@ - autossh-tunnel-client - autossh-tunnel-client-install -- include: configure.yml +- ansible.builtin.include: configure.yml tags: - configuration - autossh-tunnel-client - autossh-tunnel-client-configure -- block: - - include: service-initd.yml +- name: service + block: + - ansible.builtin.include: service-initd.yml when: is_docker_guest tags: - configuration @@ -34,13 +35,14 @@ - autossh-tunnel-client-service - autossh-tunnel-client-service-initd -- block: - - include: service-upstart.yml +- name: service + block: + - ansible.builtin.include: service-upstart.yml when: ansible_service_mgr != 'systemd' tags: - autossh-tunnel-client-service-upstart - - include: service-systemd.yml + - ansible.builtin.include: service-systemd.yml when: ansible_service_mgr == 'systemd' tags: - autossh-tunnel-client-service-systemd @@ -51,7 +53,7 @@ - autossh-tunnel-client-service - name: start and enable service - service: + ansible.builtin.service: name: autossh-tunnel-client state: "{{ service_default_state | default('started') }}" enabled: "{{ service_default_enabled | default(true) | bool }}" diff --git a/tasks/service-initd.yml b/tasks/service-initd.yml index 3e16436..9a4ab9c 100644 --- a/tasks/service-initd.yml +++ b/tasks/service-initd.yml @@ -1,7 +1,7 @@ # tasks file --- - name: service | initd | update script - template: + ansible.builtin.template: src: "{{ autossh_tunnel_client_etc_init_d_file.lstrip('/') }}.j2" dest: "{{ autossh_tunnel_client_etc_init_d_file }}" owner: root diff --git a/tasks/service-systemd.yml b/tasks/service-systemd.yml index 0c17b16..aaa3325 100644 --- a/tasks/service-systemd.yml +++ b/tasks/service-systemd.yml @@ -1,7 +1,7 @@ # tasks file --- - name: service | systemd | update script - template: + ansible.builtin.template: src: "{{ autossh_tunnel_client_etc_systemd_file.lstrip('/') }}.j2" dest: "{{ autossh_tunnel_client_etc_systemd_file }}" owner: root @@ -12,8 +12,8 @@ tags: - autossh-tunnel-client-service-systemd-update -- name: service | systemd | reload - systemd: +- name: service | systemd | reload # noqa no-handler + ansible.builtin.systemd: daemon_reload: true when: _update_systemd_script is changed tags: diff --git a/tasks/service-upstart.yml b/tasks/service-upstart.yml index 46957c3..c770f7c 100644 --- a/tasks/service-upstart.yml +++ b/tasks/service-upstart.yml @@ -1,7 +1,7 @@ # tasks file --- - name: service | upstart | update script - template: + ansible.builtin.template: src: "{{ autossh_tunnel_client_etc_init_file.lstrip('/') }}.j2" dest: "{{ autossh_tunnel_client_etc_init_file }}" owner: root diff --git a/tests/tasks/post.yml b/tests/tasks/post.yml index d880e04..778a6e5 100644 --- a/tests/tasks/post.yml +++ b/tests/tasks/post.yml @@ -1,15 +1,15 @@ # pre test file --- - name: install dependencies - apt: + ansible.builtin.apt: name: - netcat-traditional state: "{{ apt_install_state | default('latest') }}" update_cache: true cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}" -- name: check tunneled service - shell: > +- name: check tunneled service # noqa risky-shell-pipe + ansible.builtin.shell: > echo stats | nc {{ ansible_lo['ipv4']['address'] }} {{ autossh_tunnel_client_tunneled_memcached_port }} | grep -q 'STAT' && (echo 'Availability test: pass' && exit 0) diff --git a/tests/tasks/pre.yml b/tests/tasks/pre.yml index 75637c2..d604cd1 100644 --- a/tests/tasks/pre.yml +++ b/tests/tasks/pre.yml @@ -1,7 +1,7 @@ # pre test file --- - name: install dependencies - apt: + ansible.builtin.apt: name: - openssh-client state: "{{ apt_install_state | default('latest') }}" @@ -9,7 +9,7 @@ cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}" - name: add ssh directory - file: + ansible.builtin.file: path: "{{ autossh_tunnel_client_ssh_directory }}" state: directory owner: root @@ -17,25 +17,25 @@ mode: 0700 - name: generate key pair - command: > + ansible.builtin.command: > ssh-keygen -t rsa -b 2048 -C '' -P '' -f {{ autossh_tunnel_client_private_key_file }} -q args: creates: "{{ autossh_tunnel_client_private_key_file }}" - name: remove authorized_keys file (if empty) - shell: > + ansible.builtin.shell: > [ -s {{ autossh_tunnel_client_authorized_keys_file }} ] || rm -fv {{ autossh_tunnel_client_authorized_keys_file }} register: _rm_fv changed_when: _rm_fv.stdout_lines | length > 0 - name: add public key - shell: > + ansible.builtin.shell: > cat {{ autossh_tunnel_client_public_key_file }} > {{ autossh_tunnel_client_authorized_keys_file }} args: creates: "{{ autossh_tunnel_client_authorized_keys_file }}" - name: install test service - apt: + ansible.builtin.apt: name: - openssh-server - memcached diff --git a/tests/test.yml b/tests/test.yml index 641f24c..99e0675 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -5,11 +5,11 @@ become: true pre_tasks: - name: include vars - include_vars: "{{ playbook_dir }}/vars/main.yml" + ansible.builtin.include_vars: "{{ playbook_dir }}/vars/main.yml" - name: include tasks - include: "{{ playbook_dir }}/tasks/pre.yml" + ansible.builtin.include: "{{ playbook_dir }}/tasks/pre.yml" roles: - ../../ # post_tasks: # - name: include tasks -# include: "{{ playbook_dir }}/tasks/post.yml" +# ansible.builtin.include: "{{ playbook_dir }}/tasks/post.yml" diff --git a/tests/vagrant.yml b/tests/vagrant.yml index 3dfeb1c..5ff4a5e 100644 --- a/tests/vagrant.yml +++ b/tests/vagrant.yml @@ -5,11 +5,11 @@ become: true pre_tasks: - name: include vars - include_vars: "{{ playbook_dir }}/vars/main.yml" + ansible.builtin.include_vars: "{{ playbook_dir }}/vars/main.yml" - name: include tasks - include: "{{ playbook_dir }}/tasks/pre.yml" + ansible.builtin.include: "{{ playbook_dir }}/tasks/pre.yml" roles: - ../../ post_tasks: - name: include tasks - include: "{{ playbook_dir }}/tasks/post.yml" + ansible.builtin.include: "{{ playbook_dir }}/tasks/post.yml"