1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-03-09 15:40:17 +00:00

refactor for readability; try Ansible's systemd

This commit is contained in:
A Holt 2018-08-13 15:03:13 -04:00 committed by GitHub
parent fa908f04c3
commit 04be152c0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,105 +1,129 @@
---
- name: Install OpenVPN packages - name: Install OpenVPN packages
package: name={{ item }} package:
state=present name: "{{ item }}"
state: present
with_items: with_items:
- openvpn - openvpn
- nmap - nmap
tags: tags:
- download - download
- name: Create the directory for keys - name: Create the directory for keys
file: dest=/etc/openvpn/keys file:
state=directory dest: /etc/openvpn/keys
owner=root state: directory
group=root owner: root
mode=0755 group: root
mode: 0755
- name: Create the directory for scripts - name: Create the directory for scripts
file: dest=/etc/openvpn/scripts file:
state=directory dest: /etc/openvpn/scripts
owner=root state: directory
group=root owner: root
mode=0755 group: root
mode:0755
- name: Create a folder for iiab executable not on path - name: Create a folder for iiab executable not on path
file: path=/usr/lib/iiab file:
state=directory path: /usr/lib/iiab
state: directory
- name: Configure OpenVPN - name: Configure OpenVPN
template: src={{ item.src }} template:
dest={{ item.dest }} src: "{{ item.src }}"
owner={{ item.owner }} dest: "{{ item.dest }}"
group=root owner: "{{ item.owner }}"
mode={{ item.mode }} group: root
mode: "{{ item.mode }}"
with_items: with_items:
- { src: 'ca.crt', dest: '/etc/openvpn/keys/ca.crt', owner: "root" , mode: '0644' } - { src: 'ca.crt', dest: '/etc/openvpn/keys/ca.crt', owner: "root", mode: '0644' }
- { src: 'client1.crt', dest: '/etc/openvpn/keys/client1.crt', owner: "root" , mode: '0644' } - { src: 'client1.crt', dest: '/etc/openvpn/keys/client1.crt', owner: "root", mode: '0644' }
- { src: 'client1.key', dest: '/etc/openvpn/keys/client1.key', owner: "root" , mode: '0600' } - { src: 'client1.key', dest: '/etc/openvpn/keys/client1.key', owner: "root", mode: '0600' }
- { src: 'announce', dest: '/etc/openvpn/scripts/announce', owner: "root" , mode: '0755' } - { src: 'announce', dest: '/etc/openvpn/scripts/announce', owner: "root", mode: '0755' }
- { src: 'announcer', dest: '/etc/openvpn/scripts/announcer', owner: "root" , mode: '0755' } - { src: 'announcer', dest: '/etc/openvpn/scripts/announcer', owner: "root", mode: '0755' }
- { src: 'silence', dest: '/etc/openvpn/scripts/silence', owner: "root" , mode: '0755' } - { src: 'silence', dest: '/etc/openvpn/scripts/silence', owner: "root", mode: '0755' }
- { src: 'xscenet.conf', dest: '/etc/openvpn/xscenet.conf', owner: "root" , mode: '0644' } - { src: 'xscenet.conf', dest: '/etc/openvpn/xscenet.conf', owner: "root", mode: '0644' }
- { src: 'iiab-vpn.conf.in', dest: '/etc/openvpn/iiab-vpn.conf.in', owner: "root" , mode: '0644' } - { src: 'iiab-vpn.conf.in', dest: '/etc/openvpn/iiab-vpn.conf.in', owner: "root", mode: '0644' }
- { src: 'iiab-vpn', dest: '/usr/bin/iiab-vpn', owner: "root" , mode: '0755' } - { src: 'iiab-vpn', dest: '/usr/bin/iiab-vpn', owner: "root", mode: '0755' }
- { src: 'iiab-handle', dest: '/usr/bin/iiab-handle', owner: "root" , mode: '0755' } - { src: 'iiab-handle', dest: '/usr/bin/iiab-handle', owner: "root", mode: '0755' }
- { src: 'up_wan', dest: '/usr/lib/iiab/up_wan', owner: "root" , mode: '0755' } - { src: 'up_wan', dest: '/usr/lib/iiab/up_wan', owner: "root", mode: '0755' }
- { src: 'start.j2', dest: '/usr/lib/iiab/start', owner: "root" , mode: '0755' } - { src: 'start.j2', dest: '/usr/lib/iiab/start', owner: "root", mode: '0755' }
- { src: 'iiab-remote-on', dest: '/usr/bin/iiab-remote-on', owner: "root" , mode: '0755' } - { src: 'iiab-remote-on', dest: '/usr/bin/iiab-remote-on', owner: "root", mode: '0755' }
- { src: 'iiab-remote-off', dest: '/usr/bin/iiab-remote-off', owner: "root" , mode: '0755' } - { src: 'iiab-remote-off', dest: '/usr/bin/iiab-remote-off', owner: "root", mode: '0755' }
- name: Put up_wan in place for Debian - name: Put up_wan in place (debuntu)
template: src=up_wan dest=/usr/lib/iiab/up_wan template:
src: up_wan
dest: /usr/lib/iiab/up_wan
when: is_debuntu when: is_debuntu
- name: Put dispatcher up for NM - name: Put dispatcher up for NM (not debuntu)
template: src=15-openvpn dest=/etc/NetworkManager/dispatcher.d/ template:
src: 15-openvpn
dest: /etc/NetworkManager/dispatcher.d/
when: not is_debuntu when: not is_debuntu
- name: Check for manually configured OpenVPN tunnel - name: Check for manually configured OpenVPN tunnel
stat: path=/etc/openvpn/iiab-vpn.conf stat:
path: /etc/openvpn/iiab-vpn.conf
register: stat register: stat
# note that ansible does not currently handle @ in a service name # note that ansible does not currently handle @ in a service name (FIXED SOMETIME PRIOR TO AUGUST 2018??)
- name: Enable the OpenVPN tunnel at boot time - name: Enable & Start openvpn@xscenet tunnel
shell: systemctl enable openvpn@xscenet.service systemd:
when: openvpn_enabled and not stat.exists is defined and is_debuntu name: openvpn@xscenet.service
enabled: yes
state: started
when: openvpn_enabled and not stat.exists is defined
- name: Enable the OpenVPN tunnel at boot time for Debian #- name: Enable the OpenVPN tunnel at boot time (debuntu)
shell: update-rc.d openvpn enable # shell: systemctl enable openvpn@xscenet.service
when: openvpn_enabled and not stat.exists is defined and is_debuntu # when: openvpn_enabled and not stat.exists is defined and is_debuntu
- name: Start the OpenVPN tunnel now #- name: Enable the OpenVPN tunnel at boot time (debuntu)
shell: systemctl start openvpn@xscenet.service # shell: update-rc.d openvpn enable
when: openvpn_enabled and not stat.exists is defined and not installing # 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
- name: Make OpenVPN connection automatic - name: Make OpenVPN connection automatic
lineinfile: dest=/etc/crontab lineinfile:
line="25 * * * * root (/usr/bin/systemctl start openvpn@xscenet.service) > /dev/null" dest: /etc/crontab
line: "25 * * * * root (/usr/bin/systemctl start openvpn@xscenet.service) > /dev/null"
when: openvpn_enabled and openvpn_cron_enabled and not stat.exists is defined when: openvpn_enabled and openvpn_cron_enabled and not stat.exists is defined
- name: Make OpenVPN connection manual - name: Make OpenVPN connection manual
lineinfile: dest=/etc/crontab lineinfile:
regexp=".*/usr/bin/systemctl*" dest: /etc/crontab
state=absent regexp: ".*/usr/bin/systemctl*"
state: absent
when: not openvpn_enabled or not openvpn_cron_enabled when: not openvpn_enabled or not openvpn_cron_enabled
- name: Stop starting the OpenVPN tunnel at boot time - name: Disable & Stop openvpn@xscenet tunnel
shell: systemctl disable openvpn@xscenet.service systemd:
when: not openvpn_enabled and not is_debuntu name: openvpn@xscenet.service
enabled: no
state: stopped
when: not openvpn_enabled
- name: Stop starting the OpenVPN tunnel at boot time for Debian #- name: Stop starting the OpenVPN tunnel at boot time (not debuntu)
shell: update-rc.d openvpn disable # shell: systemctl disable openvpn@xscenet.service
when: not openvpn_enabled and is_debuntu # when: not openvpn_enabled and not is_debuntu
- name: Stop OpenVPN tunnel immediately #- name: Stop starting the OpenVPN tunnel at boot time (debuntu)
shell: systemctl stop openvpn@xscenet.service # shell: update-rc.d openvpn disable
ignore_errors: True # when: not openvpn_enabled and is_debuntu
when: not openvpn_enabled and not installing
#- name: Stop OpenVPN tunnel immediately
# shell: systemctl stop openvpn@xscenet.service
# ignore_errors: True
# when: not openvpn_enabled and not installing
- name: Add 'openvpn' to list of services at /etc/iiab/iiab.ini - name: Add 'openvpn' to list of services at /etc/iiab/iiab.ini