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
- name : Create the directory for 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
2017-06-09 23:25:56 +00:00
- name : Create a folder for iiab executable not on path
2018-08-13 19:03:13 +00:00
file :
path : /usr/lib/iiab
state : directory
2017-05-27 18:09:50 +00:00
2017-10-27 12:18:26 +00:00
- name : Configure OpenVPN
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 }}"
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' }
- { src: 'announcer', dest: '/etc/openvpn/scripts/announcer', mode : '0755' }
- { 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-13 20:37:58 +00:00
- { src: 'iiab-vpn.conf.in', dest: '/etc/openvpn/iiab-vpn.conf.in', mode : '0644' }
2018-08-13 20:50:47 +00:00
- { src: 'iiab-vpn.j2', dest: '/usr/bin/iiab-vpn', mode : '0755' }
- { src: 'iiab-handle.j2', dest: '/usr/bin/iiab-handle', mode : '0755' }
2018-08-13 20:37:58 +00:00
- { src: 'up_wan', dest: '/usr/lib/iiab/up_wan', mode : '0755' }
- { src: 'start.j2', dest: '/usr/lib/iiab/start', mode : '0755' }
- { src: 'iiab-remote-on', dest: '/usr/bin/iiab-remote-on', mode : '0755' }
- { src: 'iiab-remote-off', dest: '/usr/bin/iiab-remote-off', mode : '0755' }
2018-08-13 19:03:13 +00:00
2018-08-14 00:33:54 +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
2018-08-13 19:03:13 +00:00
- name : Put up_wan in place (debuntu)
template :
src : up_wan
dest : /usr/lib/iiab/up_wan
2017-05-27 23:10:45 +00:00
when : is_debuntu
2017-05-27 18:09:50 +00:00
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
2017-10-27 12:18:26 +00:00
- name : Check for manually configured OpenVPN tunnel
2018-08-13 19:03:13 +00:00
stat :
path : /etc/openvpn/iiab-vpn.conf
2017-05-27 18:09:50 +00:00
register : stat
2017-10-27 12:18:26 +00:00
2018-08-14 01:11:57 +00:00
# AUG 2018: Unexplainably, this stanza had to be placed underneath ANY
# "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-13 21:10:28 +00:00
- name : Enable & (Re)Start openvpn@xscenet tunnel
2018-08-13 19:03:13 +00:00
systemd :
name : openvpn@xscenet.service
enabled : yes
2018-08-13 21:10:28 +00:00
state : restarted
2018-08-13 19:03:13 +00:00
when : openvpn_enabled and not stat.exists is defined
2018-08-13 21:10:28 +00:00
# FIXED SOMETIME PRIOR TO AUGUST 2018: ansible [did] not handle @ in a service name
2018-08-13 19:03:13 +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
2017-05-27 18:09:50 +00:00
2018-08-13 19:03:13 +00:00
#- 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
2017-05-27 18:09:50 +00:00
2018-08-13 19:03:13 +00:00
#- name: Start the OpenVPN tunnel now
# shell: systemctl start openvpn@xscenet.service
# when: openvpn_enabled and not stat.exists is defined and not installing
2017-05-27 18:09:50 +00:00
2018-08-14 00:33:54 +00:00
- name : Enable hourly cron job for OpenVPN
2018-08-13 19:03:13 +00:00
lineinfile :
dest : /etc/crontab
line : "25 * * * * root (/usr/bin/systemctl start openvpn@xscenet.service) > /dev/null"
2017-10-27 12:18:26 +00:00
when : openvpn_enabled and openvpn_cron_enabled and not stat.exists is defined
2017-05-27 18:09:50 +00:00
2018-08-14 00:33:54 +00:00
- name : Remove hourly cron jobs for OpenVPN
2018-08-13 19:03:13 +00:00
lineinfile :
dest : /etc/crontab
2018-08-14 00:33:54 +00:00
regexp : "openvpn@xscenet"
#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-08-13 19:03:13 +00:00
- name : Disable & Stop openvpn@xscenet tunnel
systemd :
name : openvpn@xscenet.service
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-08-14 00:48:40 +00:00
value : "OpenVPN is a means of connecting to others anywhere on the internet, via a middleman server, using Virtual Private Network techniques to create secure connections."
2017-11-27 01:19:45 +00:00
- option : enabled
value : "{{ openvpn_enabled }}"
2018-08-13 19:48:28 +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 }}"