Skip to content

Commit

Permalink
Merge pull request #3 from Oefenweb/consistency-changes
Browse files Browse the repository at this point in the history
Consistency changes
  • Loading branch information
tersmitten authored Jan 10, 2017
2 parents b8ffad5 + 2103d1d commit dcb75a1
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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) [![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-autossh--tunnel--client-blue.svg)](https://galaxy.ansible.com/list#/roles/4773)
[![Build Status](https://travis-ci.org/Oefenweb/ansible-autossh-tunnel-client.svg?branch=master)](https://travis-ci.org/Oefenweb/ansible-autossh-tunnel-client) [![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-autossh--tunnel--client-blue.svg)](https://galaxy.ansible.com/tersmitten/autossh-tunnel-client)

Set up a persistent tunnel (using `autossh`) in Ubuntu systems (client side).

Expand Down
7 changes: 7 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ boxes = [
:cpu => "50",
:ram => "256"
},
{
:name => "ubuntu-1604",
:box => "bento/ubuntu-16.04",
:ip => '10.0.0.13',
:cpu => "50",
:ram => "256"
},
]

Vagrant.configure("2") do |config|
Expand Down
1 change: 1 addition & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ galaxy_info:
versions:
- precise
- trusty
- xenial
galaxy_tags:
- system
- networking
Expand Down
22 changes: 12 additions & 10 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,21 @@
- autossh-tunnel-client-configuration
- autossh-tunnel-client-configuration-keys

- name: create init script
template:
src: etc/init/autossh-tunnel-client.conf.j2
dest: /etc/init/autossh-tunnel-client.conf
owner: root
group: root
mode: 0644
notify: restart autossh-tunnel-client
- include: service-upstart.yml
when: ansible_distribution_version | version_compare('15.04', '<')
tags:
- configuration
- autossh-tunnel-client
- autossh-tunnel-client-configuration
- autossh-tunnel-client-configuration-init
- autossh-tunnel-client-service
- autossh-tunnel-client-service-upstart

- include: service-systemd.yml
when: ansible_distribution_version | version_compare('15.04', '>=')
tags:
- configuration
- autossh-tunnel-client
- autossh-tunnel-client-service
- autossh-tunnel-client-service-systemd

- name: start and enable service
service:
Expand Down
19 changes: 19 additions & 0 deletions tasks/service-systemd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# tasks file for autossh-tunnel-client
---
- name: service | systemd | update script
template:
src: templates/lib/systemd/system/autossh-tunnel-client.j2
dest: /lib/systemd/system/autossh-tunnel-client.service
owner: root
group: root
mode: 0644
register: _update_systemd_script
notify: restart autossh-tunnel-client
tags:
- autossh-tunnel-client-service-systemd-update

- name: service | systemd | reload
command: systemctl daemon-reload
when: _update_systemd_script | changed
tags:
- autossh-tunnel-client-service-systemd-reload
12 changes: 12 additions & 0 deletions tasks/service-upstart.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# tasks file for autossh-tunnel-client
---
- name: service | upstart | update script
template:
src: etc/init/autossh-tunnel-client.conf.j2
dest: /etc/init/autossh-tunnel-client.conf
owner: root
group: root
mode: 0644
notify: restart autossh-tunnel-client
tags:
- autossh-tunnel-client-service-upstart-update
11 changes: 5 additions & 6 deletions templates/etc/init/autossh-tunnel-client.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
description "Set up a persistent tunnel (using autossh)"
author "Mischa ter Smitten"

start on net-device-up IFACE=eth0
start on net-device-up
stop on runlevel [01S6]

respawn
respawn limit 5 60 # Respawn max 5 times in 60 seconds
respawn limit unlimited
umask 022

pre-start script
test -x /usr/bin/autossh || { stop; exit 0; }

mkdir -p -m0755 {{ autossh_tunnel_client_autossh_pidfile | dirname }}
/usr/bin/test -x {{ autossh_tunnel_client_install_prefix }}/autossh || { stop; exit 0; }
/usr/bin/install -d -m 0755 {{ autossh_tunnel_client_autossh_pidfile | dirname }}
end script

script
Expand All @@ -26,7 +25,7 @@ script
export AUTOSSH_PIDFILE={{ autossh_tunnel_client_autossh_pidfile }}
export AUTOSSH_POLL={{ autossh_tunnel_client_autossh_poll }}

autossh -M 0 -4 -N {% for forward in autossh_tunnel_client_forward %}-L {{ forward }} {% endfor %}{{ autossh_tunnel_client_user }}@{{ autossh_tunnel_client_host }} \
{{ autossh_tunnel_client_install_prefix }}/autossh -M 0 -4 -N {% for forward in autossh_tunnel_client_forward %}-L {{ forward }} {% endfor %}{{ autossh_tunnel_client_user }}@{{ autossh_tunnel_client_host }} \
-p {{ autossh_tunnel_client_port }} \
-i {{ autossh_tunnel_client_configuration_directory }}/{{ autossh_tunnel_client_identity }} \
{% for ssh_options in autossh_tunnel_client_ssh_options %}
Expand Down
27 changes: 27 additions & 0 deletions templates/lib/systemd/system/autossh-tunnel-client.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
; {{ ansible_managed }}

[Unit]
Description=Set up a persistent tunnel (using autossh)
After=network.target

[Service]
Type=simple
Environment=AUTOSSH_DEBUG={{ autossh_tunnel_client_autossh_debug }}
Environment=AUTOSSH_FIRST_POLL={{ autossh_tunnel_client_autossh_first_poll }}
Environment=AUTOSSH_GATETIME={{ autossh_tunnel_client_autossh_gatetime }}
Environment=AUTOSSH_LOGLEVEL={{ autossh_tunnel_client_autossh_loglevel }}
Environment=AUTOSSH_PIDFILE={{ autossh_tunnel_client_autossh_pidfile }}
Environment=AUTOSSH_POLL={{ autossh_tunnel_client_autossh_poll }}
ExecStartPre=/usr/bin/test -x {{ autossh_tunnel_client_install_prefix }}/autossh
ExecStartPre=/usr/bin/install -d -m 0755 {{ autossh_tunnel_client_autossh_pidfile | dirname }}
ExecStart={{ autossh_tunnel_client_install_prefix }}/autossh -M 0 -4 -N {% for forward in autossh_tunnel_client_forward %}-L {{ forward }} {% endfor %}{{ autossh_tunnel_client_user }}@{{ autossh_tunnel_client_host }} \
-p {{ autossh_tunnel_client_port }} \
-i {{ autossh_tunnel_client_configuration_directory }}/{{ autossh_tunnel_client_identity }} \
{% for ssh_options in autossh_tunnel_client_ssh_options %}
-o "{{ ssh_options }}" \
{% endfor %}

Restart=always

[Install]
WantedBy=multi-user.target
1 change: 1 addition & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ autossh_tunnel_client_dependencies:
- autossh

autossh_tunnel_client_configuration_directory: /etc/autossh
autossh_tunnel_client_install_prefix: /usr/bin

0 comments on commit dcb75a1

Please sign in to comment.