Skip to content

Commit

Permalink
Merge pull request #9 from Oefenweb/consistency-changes
Browse files Browse the repository at this point in the history
Consistency changes
  • Loading branch information
tersmitten authored Jul 21, 2022
2 parents 966c15d + c1019e4 commit ceeb5bf
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 54 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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
Expand Down
13 changes: 8 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
FROM ubuntu:16.04
FROM ubuntu:18.04
MAINTAINER Mischa ter Smitten <[email protected]>

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
Expand Down
2 changes: 1 addition & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
@@ -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'
5 changes: 2 additions & 3 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
6 changes: 6 additions & 0 deletions molecule/default/collections.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
collections:
- name: community.docker
version: '>=1.2.0,<2'
- name: community.general
version: '>=2,<3'
2 changes: 1 addition & 1 deletion molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
- ../../../
4 changes: 2 additions & 2 deletions molecule/default/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
12 changes: 6 additions & 6 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 3 additions & 0 deletions requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# requirements file
---
collections: []
6 changes: 3 additions & 3 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# tasks file
---
- name: configure | create directories
file:
ansible.builtin.file:
path: "{{ item.dest }}"
state: directory
owner: root
Expand All @@ -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
Expand All @@ -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) }}"
Expand Down
20 changes: 11 additions & 9 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# 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
- autossh-tunnel-client
- 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
Expand All @@ -19,28 +19,30 @@
- 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
- autossh-tunnel-client
- 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
Expand All @@ -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 }}"
Expand Down
2 changes: 1 addition & 1 deletion tasks/service-initd.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions tasks/service-systemd.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tasks/service-upstart.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/tasks/post.yml
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
12 changes: 6 additions & 6 deletions tests/tasks/pre.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
# pre test file
---
- name: install dependencies
apt:
ansible.builtin.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
file:
ansible.builtin.file:
path: "{{ autossh_tunnel_client_ssh_directory }}"
state: directory
owner: root
group: root
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
Expand Down
6 changes: 3 additions & 3 deletions tests/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 3 additions & 3 deletions tests/vagrant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit ceeb5bf

Please sign in to comment.