2018-08-13 19:20:12 +00:00
- name : Install OpenVPN and Nmap packages
2018-08-13 19:03:13 +00:00
package :
name : "{{ item }}"
state : present
2017-05-27 18:09:50 +00:00
with_items :
2018-08-13 19:03:13 +00:00
- openvpn
- nmap
2017-05-27 18:09:50 +00:00
tags :
- download
2018-08-20 21:10:03 +00:00
- name : Install ssh public keys for remote support (if openvpn_install)
2018-08-20 20:02:05 +00:00
lineinfile :
2018-08-20 21:10:03 +00:00
line : "{{ item.pubkey }}"
2018-08-20 21:15:05 +00:00
regexp : "{{ item.regexp }}"
2018-08-20 20:02:05 +00:00
path : /root/.ssh/authorized_keys
2018-08-20 21:10:03 +00:00
#backup: yes
2018-08-20 20:02:05 +00:00
when : openvpn_install
with_items :
2018-08-20 21:15:05 +00:00
- regexp : "LvCSAAcfYIdZPR4ePVpVUZ/IbkGjpQSoRMa5HuVjMO3cZNR27ptqjNjq2husJOyhMFCOBTzo4thioGyTpBr4u3s=$" # Tim Moody
2018-08-20 21:10:03 +00:00
pubkey : "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAhlQIh8ZPx4awdM0O6QNcPbx3qIZ39FHjF2YJ2SX3z7iLnYiz03Ek6Bux9P4HvaVAqlApiz2I68Vq8TfU2s/+LvCSAAcfYIdZPR4ePVpVUZ/IbkGjpQSoRMa5HuVjMO3cZNR27ptqjNjq2husJOyhMFCOBTzo4thioGyTpBr4u3s="
2018-08-20 21:15:05 +00:00
- regexp : "tUM4hl009fbXY4Yy3bAadWL1CquVrZmKfBBWhyhz8zLD6TQ== ghunt@ip-192-168-123-123.ec2.internal$"
2018-08-20 21:10:03 +00:00
pubkey : "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxAmjU7VojyK+0Pjp2p8CCGTNBtE565A/L8IVbAT8MIucRE9LN1g5LjGnOHUShFJpwuTR1JLX2r9EDRMsf9MmyTgUAnuyP005giWVHXLPtjyjTzbsJ1DEtXRytulmF+GlCOaqPWNde6EOmReqPHbmjIQpRZ/Sc8hziS4jVSQuBA9EhaBmZ62CPqK33mPJvnpwMtdd6nHXAcXsZhStd3NhVDm27+B3sHI6mr2w7ExdBXE5DKiZL2po8n2y4hJYZreJopbjcQmv4oWdDWvPu5I92xDgYCsqcE7zSrv1um+tUM4hl009fbXY4Yy3bAadWL1CquVrZmKfBBWhyhz8zLD6TQ== ghunt@ip-192-168-123-123.ec2.internal"
2018-08-20 21:15:05 +00:00
- regexp : "heOMXXNU6skxdPh2fcHh0bzQcaCSQ== holt@crank$"
2018-08-20 21:10:03 +00:00
pubkey : "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEApHPly+EA1M4bispl3AulTLjyYCjcJzh6s779K3epDkqh600a+fHsdIiddWCAfIonRq+9MJyOiaNQ+WYLOuajI1IiFZWFt45xDAiyCUnyuT+ytAX+IA3TgTwgTZPfzDOzI8rDRV9Sgl+LZLfPno7T3qxcGx2l51bRk+koRK+Txpph//M3jGvsFmTKhjvfxgEIUmMH9SkASxEdyqASr0+/+uLR92MnT+8CT1pOYYoJyZp9Lta5eGqJvbEmd3Dn7MXqD3vXE57o4rBJ0bR3q5LK59WVNxNQbulJ9z5V7aTJ4AbBFQWxm0fH0gBx+heOMXXNU6skxdPh2fcHh0bzQcaCSQ== holt@crank"
# CLARIF: plus signs (+) in public keys cause duplicate key additions (above)
# and failure during removal (below) as "+" has a special meaning as
2018-08-20 21:21:40 +00:00
# interpreted in a Python regexp, as implemented by Ansible's lineinfile module:
2018-08-20 21:10:03 +00:00
# https://docs.python.org/2/library/re.html
# WORKAROUND: the tail end of each public key (after the last plus sign) is
2018-08-20 21:21:40 +00:00
# being used (instead of the full key) as an abbreviated regexp for now.
2018-08-20 21:10:03 +00:00
# A backslash in front of each plus sign (+) would also work.
2018-08-20 20:02:05 +00:00
2018-08-20 21:10:03 +00:00
- name : Remove ssh public keys (if openvpn_install is False)
2018-08-20 20:02:05 +00:00
lineinfile :
regexp : "{{ item }}"
path : /root/.ssh/authorized_keys
state : absent
2018-08-20 21:10:03 +00:00
#backup: yes
2018-08-20 20:02:05 +00:00
when : not openvpn_install
with_items :
2018-08-20 20:27:56 +00:00
- "LvCSAAcfYIdZPR4ePVpVUZ/IbkGjpQSoRMa5HuVjMO3cZNR27ptqjNjq2husJOyhMFCOBTzo4thioGyTpBr4u3s=$"
- "tUM4hl009fbXY4Yy3bAadWL1CquVrZmKfBBWhyhz8zLD6TQ== ghunt@ip-192-168-123-123.ec2.internal$"
- "heOMXXNU6skxdPh2fcHh0bzQcaCSQ== holt@crank$"
2018-08-20 20:02:05 +00:00
2018-08-20 21:10:03 +00:00
- name : Create the directory for OpenVPN keys
2018-08-13 19:03:13 +00:00
file :
dest : /etc/openvpn/keys
state : directory
owner : root
group : root
mode : 0755
2017-05-27 18:09:50 +00:00
2017-10-19 06:33:02 +00:00
- name : Create the directory for scripts
2018-08-13 19:03:13 +00:00
file :
dest : /etc/openvpn/scripts
state : directory
owner : root
group : root
2018-08-13 19:05:29 +00:00
mode : 0755
2017-05-27 18:09:50 +00:00
2018-08-15 20:38:15 +00:00
# Comment out in future? Might still be relevant for CentOS but unused for ~2 years as of August 2018:
2018-08-15 18:28:09 +00:00
- name : Create folder /usr/lib/iiab (not on path) for iiab executable up_wan
2018-08-13 19:03:13 +00:00
file :
path : /usr/lib/iiab
state : directory
2017-05-27 18:09:50 +00:00
2018-08-15 20:38:15 +00:00
- name : Configure OpenVPN (BACKS UP FILES IF CHANGED)
2018-08-13 19:03:13 +00:00
template :
src : "{{ item.src }}"
dest : "{{ item.dest }}"
2018-08-13 20:37:58 +00:00
owner : root
2018-08-13 19:03:13 +00:00
group : root
mode : "{{ item.mode }}"
2018-08-15 20:38:15 +00:00
backup : yes
2017-05-27 18:09:50 +00:00
with_items :
2018-08-13 20:37:58 +00:00
- { src: 'ca.crt', dest: '/etc/openvpn/keys/ca.crt', mode : '0644' }
- { src: 'client1.crt', dest: '/etc/openvpn/keys/client1.crt', mode : '0644' }
- { src: 'client1.key', dest: '/etc/openvpn/keys/client1.key', mode : '0600' }
- { src: 'announce', dest: '/etc/openvpn/scripts/announce', mode : '0755' }
2018-08-14 04:35:48 +00:00
- { src: 'announcer.j2', dest: '/etc/openvpn/scripts/announcer', mode : '0755' }
2018-08-13 20:37:58 +00:00
- { src: 'silence', dest: '/etc/openvpn/scripts/silence', mode : '0755' }
2018-08-13 20:50:47 +00:00
- { src: 'xscenet.conf.j2', dest: '/etc/openvpn/xscenet.conf', mode : '0644' }
2018-08-15 20:33:11 +00:00
- { src: 'iiab-remote-on.j2', dest: '/usr/bin/iiab-remote-on', mode : '0755' }
- { src: 'iiab-remote-off', dest: '/usr/bin/iiab-remote-off', mode : '0755' }
2018-08-15 20:38:15 +00:00
- { src: 'openvpn_handle.j2', dest: '/etc/iiab/openvpn_handle', mode : '0644' }
2018-08-15 20:33:11 +00:00
# Comment out in future? Not recommended as of August 2018:
2018-08-13 20:50:47 +00:00
- { src: 'iiab-handle.j2', dest: '/usr/bin/iiab-handle', mode : '0755' }
2018-08-15 20:33:11 +00:00
# Comment out in future? Might still be relevant for CentOS but unused for ~2 years as of August 2018:
2018-08-13 20:37:58 +00:00
- { src: 'up_wan', dest: '/usr/lib/iiab/up_wan', mode : '0755' }
2018-08-15 18:52:40 +00:00
# Unused for ~2 years as of August 2018:
2018-08-15 18:12:37 +00:00
#- { src: 'start.j2', dest: '/usr/lib/iiab/start', mode: '0755' }
2018-08-15 20:33:11 +00:00
# Buggy & rarely used as of August 2018:
#- { src: 'iiab-vpn.conf.in', dest: '/etc/openvpn/iiab-vpn.conf.in', mode: '0644' }
# Buggy & rarely used as of August 2018:
#- { src: 'iiab-vpn.j2', dest: '/usr/bin/iiab-vpn', mode: '0755' }
2018-08-13 19:03:13 +00:00
2018-08-15 20:38:15 +00:00
#- name: Save openvpn_handle variable into /etc/iiab/openvpn_handle (BACKS UP FILE IF CHANGED)
# template:
# src: openvpn_handle.j2
# dest: /etc/iiab/openvpn_handle
# owner: root
# group: root
# mode: 0644
# backup: yes
# when: openvpn_handle is defined
2018-08-14 00:33:54 +00:00
2018-08-16 01:25:22 +00:00
# up_wan was being installed twice (also above) and was unused for ~2 years
# as of August 2018: (see 15-openvpn below)
2018-08-15 18:12:37 +00:00
#- name: Put up_wan in place (debuntu)
# template:
# src: up_wan
# dest: /usr/lib/iiab/up_wan
# when: is_debuntu
2017-05-27 18:09:50 +00:00
2018-08-15 18:57:15 +00:00
# Comment out in future? Contained serious bug (15-openvpn called
2018-08-16 01:32:56 +00:00
# up-wan instead of up_wan in /usr/lib/iiab/ as of August 2018) so
# evidently unused for ~2 years:
2018-08-13 19:03:13 +00:00
- name : Put dispatcher up for NM (not debuntu)
template :
src : 15 -openvpn
dest : /etc/NetworkManager/dispatcher.d/
2017-05-27 23:10:45 +00:00
when : not is_debuntu
2017-05-27 18:09:50 +00:00
2018-08-15 20:33:11 +00:00
# Was buggy & unused for ~2 years as of August 2018:
#- name: Check for manually configured OpenVPN tunnel
# stat:
# path: /etc/openvpn/iiab-vpn.conf
# register: stat
2017-05-27 18:09:50 +00:00
2017-10-27 12:18:26 +00:00
2018-08-14 01:55:31 +00:00
# FIXED SOMETIME PRIOR TO AUGUST 2018: earlier versions of Ansible had not
# been working with systemd service names that contained the "@" character.
2018-08-14 01:34:09 +00:00
#- name: Enable the OpenVPN tunnel at boot time (debuntu)
# shell: systemctl enable openvpn@xscenet.service
# when: openvpn_enabled and not stat.exists is defined and is_debuntu
#- name: Enable the OpenVPN tunnel at boot time (debuntu)
# shell: update-rc.d openvpn enable
# when: openvpn_enabled and not stat.exists is defined and is_debuntu
#- name: Start the OpenVPN tunnel now
# shell: systemctl start openvpn@xscenet.service
# when: openvpn_enabled and not stat.exists is defined and not installing
# AUGUST 2018: Unexplainably, stanza below had to be placed underneath ANY
2018-08-14 01:11:57 +00:00
# "lineinfile: ... state: absent" stanza to make openvpn_handle propagate
# properly to xscenet.net (monitoring ncat's erroneous handle parameter by
# observing "systemctl status openvpn@xscenet" helped trace the [primary?]
# bug to roles/openvpn/templates/announcer [far better now if not perfect?])
2018-08-14 01:17:51 +00:00
# Earlier "./runrole openvpn" had to be run twice to transmit
# /etc/iiab/openvpn_handle to xscenet.net -- and
# "systemctl restart openvpn@xscenet" was failing completely (no matter how
# many times it was run) to transmit /etc/iiab/openvpn_handle to xscenet.net
2018-09-02 21:46:30 +00:00
- name : Enable & (Re)Start PARENT service openvpn, which (re)starts CHILD service openvpn@xscenet (& actual tunnel)
2018-08-13 19:03:13 +00:00
systemd :
2018-09-02 21:31:11 +00:00
name : openvpn
daemon_reload : yes
2018-08-13 19:03:13 +00:00
enabled : yes
2018-08-13 21:10:28 +00:00
state : restarted
2018-08-15 20:33:11 +00:00
when : openvpn_enabled
2018-08-13 19:03:13 +00:00
2018-09-02 21:37:00 +00:00
- name : Enable hourly cron job for OpenVPN (typically for CentOS only?)
2018-08-13 19:03:13 +00:00
lineinfile :
2018-08-14 01:34:09 +00:00
path : /etc/crontab
2018-08-13 19:03:13 +00:00
line : "25 * * * * root (/usr/bin/systemctl start openvpn@xscenet.service) > /dev/null"
2018-08-15 20:33:11 +00:00
when : openvpn_enabled and openvpn_cron_enabled
2017-05-27 18:09:50 +00:00
2018-09-02 21:37:00 +00:00
- name : Remove hourly cron job for OpenVPN (typically for CentOS only?)
2018-08-13 19:03:13 +00:00
lineinfile :
2018-08-14 01:34:09 +00:00
path : /etc/crontab
2018-08-14 00:33:54 +00:00
regexp : "openvpn@xscenet"
2018-08-14 01:34:09 +00:00
# Potentially DANGEROUS as others use systemctl too:
2018-08-14 00:33:54 +00:00
#regexp: ".*/usr/bin/systemctl*"
2018-08-13 19:03:13 +00:00
state : absent
2017-10-27 12:18:26 +00:00
when : not openvpn_enabled or not openvpn_cron_enabled
2017-05-27 18:09:50 +00:00
2018-09-02 21:46:30 +00:00
- name : Disable & Stop PARENT service openvpn, which stops CHILD service openvpn@xscenet (& actual tunnel)
2018-08-13 19:03:13 +00:00
systemd :
2018-09-02 21:31:11 +00:00
name : openvpn
2018-08-13 19:03:13 +00:00
enabled : no
state : stopped
when : not openvpn_enabled
#- name: Stop starting the OpenVPN tunnel at boot time (not debuntu)
# shell: systemctl disable openvpn@xscenet.service
# when: not openvpn_enabled and not is_debuntu
2017-05-27 18:09:50 +00:00
2018-08-13 19:03:13 +00:00
#- name: Stop starting the OpenVPN tunnel at boot time (debuntu)
# shell: update-rc.d openvpn disable
# when: not openvpn_enabled and is_debuntu
2017-05-27 18:09:50 +00:00
2018-08-13 19:03:13 +00:00
#- name: Stop OpenVPN tunnel immediately
# shell: systemctl stop openvpn@xscenet.service
# ignore_errors: True
# when: not openvpn_enabled and not installing
2017-10-27 12:18:26 +00:00
2017-05-27 18:09:50 +00:00
2017-11-27 01:08:50 +00:00
- name : Add 'openvpn' to list of services at /etc/iiab/iiab.ini
2017-11-27 01:19:45 +00:00
ini_file :
dest : "{{ service_filelist }}"
section : openvpn
option : "{{ item.option }}"
value : "{{ item.value }}"
2017-05-27 18:09:50 +00:00
with_items :
2017-11-27 01:19:45 +00:00
- option : name
value : OpenVPN
- option : description
2018-09-02 21:37:00 +00:00
value : "OpenVPN enables live/remote support by connecting machines anywhere on the Internet, via a middleman server, using Virtual Private Network (VPN) techniques to create secure connections."
2017-11-27 01:19:45 +00:00
- option : enabled
value : "{{ openvpn_enabled }}"
2018-08-16 17:24:39 +00:00
# openvpn_handle variable can no longer be left completely undefined of August 2018 (EMPTY STRING "" IS TOLERATED, in which case OpenVPN server should use /etc/iiab/uuid in lieu of the handle)
2018-08-15 20:40:04 +00:00
- option : handle
value : "{{ openvpn_handle }}"
2017-11-27 01:19:45 +00:00
- option : cron_enabled
value : "{{ openvpn_cron_enabled }}"
2018-08-13 19:48:28 +00:00
- option : server
value : "{{ openvpn_server }}"
- option : server_virtual_ip
value : "{{ openvpn_server_virtual_ip }}"
- option : server_port
value : "{{ openvpn_server_port }}"