aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2017-03-13 13:41:59 -0400
committerB Stack <bgstack15@gmail.com>2017-03-13 13:41:59 -0400
commitbb4ab4dec95b9dc2a33b196f8d973c81c0f5fc00 (patch)
treecabf7d9b887bc9c4c5f2f2d6574d127fe6670b4c
downloadansible-ssh-tunnel-for-proxy-master.tar.gz
ansible-ssh-tunnel-for-proxy-master.tar.bz2
ansible-ssh-tunnel-for-proxy-master.zip
initial commitHEADmaster
-rw-r--r--handlers/main.yml5
-rw-r--r--main.yml18
-rw-r--r--readme.txt27
-rw-r--r--tasks/main.yml21
-rw-r--r--vars/main.yml11
5 files changed, 82 insertions, 0 deletions
diff --git a/handlers/main.yml b/handlers/main.yml
new file mode 100644
index 0000000..df6cede
--- /dev/null
+++ b/handlers/main.yml
@@ -0,0 +1,5 @@
+---
+# File: /etc/ansible/roles/use-proxy/handlers/main.yml
+
+- name: stop ssh tunnel
+ shell: ps -ef | grep -iE -- "ss[h].*{{local_proxy_port}}" | awk '{print $2}' | xargs kill -9
diff --git a/main.yml b/main.yml
new file mode 100644
index 0000000..96961e6
--- /dev/null
+++ b/main.yml
@@ -0,0 +1,18 @@
+---
+# File: /etc/ansible/roles/use-proxy/main.yml
+# Author: bgstack15
+# Startdate: 2017-03-13 10:30
+# Title: Ansible Role That Initializes an SSH Reverse Tunnel for http_proxy
+# Purpose: To make it easy to yum update on hosts that cannot reach repos normally
+# Usage:
+# Reference:
+# Improve:
+# Document: Spread out within this directory
+
+- hosts: all
+ tasks:
+ - include: tasks/main.yml
+ handlers:
+ - handlers/main.yml
+ vars_files:
+ - vars/main.yml
diff --git a/readme.txt b/readme.txt
new file mode 100644
index 0000000..a310954
--- /dev/null
+++ b/readme.txt
@@ -0,0 +1,27 @@
+# File: /etc/ansible/roles/use-proxy/readme.txt
+
+# Overview
+This ansible role, use-proxy, is designed to make it easier for ansible to set up a reverse ssh tunnel to a host that is running a web proxy, for tasks to use that proxy.
+
+# How to configure
+Check out vars/main.yml and update these values:
+
+proxy_port: 3128
+local_proxy_port: "{{proxy_port}}"
+proxy_server: tunnel@server@example.net
+proxy_server_ssh_port: 22
+
+# Dependencies
+* An available ssh host that also provides a web proxy, such as apache with a proxy config or squid.
+* Automatic ssh authentication to that server. You can use anything that provides this, but ssh keys is the easiest.
+
+# How to use in a playbook
+Just comment the - use-proxy item in the roles list to exclude the proxy.
+---
+- name: Playbook that uses an ssh tunnel for http_proxy
+ hosts: test
+ remote_user: root
+ environment: "{{ proxy_env | default(omit) }}"
+ roles:
+ - use-proxy
+ - example
diff --git a/tasks/main.yml b/tasks/main.yml
new file mode 100644
index 0000000..7528acb
--- /dev/null
+++ b/tasks/main.yml
@@ -0,0 +1,21 @@
+---
+# File: /etc/ansible/roles/use-proxy/tasks/main.yml
+
+- name: clear any ssh tunnel
+ shell: ps -ef | grep -iE -- "ss[h].*{{local_proxy_port}}" | awk '{print $2}' | xargs kill -9
+ ignore_errors: yes
+
+- name: start ssh tunnel
+ shell: nohup ssh -N -p {{proxy_server_ssh_port}} {{proxy_server}} -L {{local_proxy_port}}/localhost/{{proxy_port}} &
+ notify: stop ssh tunnel
+
+## execute task with the proxy
+#- name: execute task
+# get_url:
+# dest: /tmp/
+# url: http://albion320.no-ip.biz/smith122/repo/
+# register: env
+# environment: "{{proxy_env}}"
+
+#- debug:
+# var: env
diff --git a/vars/main.yml b/vars/main.yml
new file mode 100644
index 0000000..92b9634
--- /dev/null
+++ b/vars/main.yml
@@ -0,0 +1,11 @@
+---
+# File: /etc/ansible/roles/use-proxy/vars/main.yml
+
+proxy_port: 3128
+local_proxy_port: "{{proxy_port}}"
+proxy_server: tunnel@demo.example.com
+proxy_server_ssh_port: 22
+
+proxy_env:
+ http_proxy: "http://localhost:{{local_proxy_port}}"
+ https_proxy: "http://localhost:{{local_proxy_port}}"
bgstack15