xoxys.unifi/tasks/install.yml

108 lines
2.9 KiB
YAML
Raw Normal View History

2018-07-08 16:50:35 +00:00
---
2018-07-10 21:01:22 +00:00
- name: Setup directories
file:
path: "{{ item }}"
state: directory
owner: "{{ unifi_user }}"
group: "{{ unifi_group }}"
recurse: True
with_items:
- "{{ unifi_base_dir }}"
- "{{ unifi_base_dir }}/{{ unifi_version }}"
2018-07-10 21:11:32 +00:00
- "{{ unifi_tmp_dir }}"
2018-07-10 21:01:22 +00:00
become: True
2018-07-08 20:36:54 +00:00
- block:
- name: Download unifi version '{{ unifi_version }}'
get_url:
url: "https://dl.ubnt.com/unifi/{{ unifi_version }}/UniFi.unix.zip"
dest: /tmp/UniFi.unix.zip
force: true
2018-07-08 20:36:54 +00:00
- name: Setup unifi version '{{ unifi_version }}'
unarchive:
src: /tmp/UniFi.unix.zip
2018-07-08 20:36:54 +00:00
dest: "{{ unifi_base_dir }}/{{ unifi_version }}"
remote_src: yes
2018-07-08 20:31:07 +00:00
- name: Cleanup
file:
path: /tmp/UniFi.unix.zip
state: absent
2018-07-08 20:36:54 +00:00
become: True
become_user: "{{ unifi_user }}"
2018-07-11 23:27:26 +00:00
when: unifi_version is version(unifi_current_version, ">") or unifi_current_version is version('0.0.0', "=")
2018-07-08 21:35:10 +00:00
2018-07-11 22:31:16 +00:00
- block:
- name: Remove data folder from new version
file:
2018-07-11 23:34:46 +00:00
path: "{{ unifi_base_dir }}/{{ unifi_version }}//UniFi/data"
2018-07-11 22:31:16 +00:00
state: absent
2018-07-12 21:02:27 +00:00
- name: Stop service while restore process
systemd:
state: stopped
enabled: yes
name: unifi
2018-07-11 22:31:16 +00:00
- name: Copy data folder from previews version
synchronize:
2018-07-11 23:33:43 +00:00
src: "{{ unifi_base_dir }}/{{ unifi_current_version }}/UniFi/data"
2018-07-11 23:47:58 +00:00
dest: "{{ unifi_base_dir }}/{{ unifi_version }}/UniFi"
2018-07-11 22:31:16 +00:00
delegate_to: "{{ inventory_hostname }}"
2018-07-12 21:02:27 +00:00
- name: Start service after restore process
systemd:
state: started
enabled: yes
name: unifi
2018-07-11 22:31:16 +00:00
become: True
become_user: "{{ unifi_user }}"
when:
2018-07-11 23:27:26 +00:00
- unifi_version is version(unifi_current_version, ">")
2018-07-11 22:31:16 +00:00
- unifi_restore_after_upgrade
2018-07-11 21:08:25 +00:00
2018-07-08 21:35:10 +00:00
- name: Create symlink for latest version
file:
src: "{{ unifi_base_dir }}/{{ unifi_version }}"
dest: "{{ unifi_base_dir }}/latest"
state: link
notify: __unifi_restart
become: True
become_user: "{{ unifi_user }}"
2018-07-08 21:02:55 +00:00
- block:
2018-07-11 20:37:44 +00:00
- name: Open ports in iptables
iptables_raw:
2018-07-11 22:48:14 +00:00
name: "{{ item.name }}"
rules: "{{ item.rules }}"
state: "{{ item.state }}"
weight: "{{ item.weight|default(omit) }}"
table: "{{ item.table|default(omit) }}"
with_items: "{{ unifi_open_ports }}"
loop_control:
label: "{{item.name}}"
2018-07-11 20:40:37 +00:00
when: unifi_iptables_enabled
2018-07-11 20:37:44 +00:00
2018-07-08 21:02:55 +00:00
- name: Create systemd unit files
template:
src: "etc/systemd/system/unifi.service.j2"
dest: "/etc/systemd/system/unifi.service"
mode: 0644
notify:
- __unifi_restart
- name: Ensure service is up and running
systemd:
state: started
daemon_reload: yes
enabled: yes
name: unifi
2018-07-08 21:35:10 +00:00
- name: Set current version to custom fact
template:
2018-07-10 21:33:46 +00:00
src: etc/ansible/facts.d/unifi.fact.j2
dest: /etc/ansible/facts.d/unifi.fact
2018-07-11 23:42:06 +00:00
when: unifi_version is version(unifi_current_version, ">") or unifi_current_version is version('0.0.0', "=")
2018-07-08 21:02:55 +00:00
become: True