xoxys.unifi/tasks/install.yml

115 lines
3.2 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-08-18 14:22:31 +00:00
become_user: root
2018-07-10 21:01:22 +00:00
2018-07-08 20:36:54 +00:00
- block:
2019-01-09 21:11:03 +00:00
- 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
2019-01-09 21:11:03 +00:00
- name: Setup unifi version '{{ unifi_version }}'
unarchive:
src: /tmp/UniFi.unix.zip
dest: "{{ unifi_base_dir }}/{{ unifi_version }}"
remote_src: yes
2018-07-08 20:31:07 +00:00
2019-01-09 21:11:03 +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 }}"
2019-01-09 21:11:03 +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:
2019-01-09 21:11:03 +00:00
- name: Remove data folder from new version
file:
path: "{{ unifi_base_dir }}/{{ unifi_version }}//UniFi/data"
state: absent
become: True
become_user: "{{ unifi_user }}"
2018-07-11 22:31:16 +00:00
2019-01-09 21:11:03 +00:00
- name: Stop service while restore process
systemd:
state: stopped
enabled: yes
name: unifi
become: True
become_user: root
2018-07-12 21:02:27 +00:00
2019-01-09 21:11:03 +00:00
- name: Copy data folder from previews version
synchronize:
src: "{{ unifi_base_dir }}/{{ unifi_current_version }}/UniFi/data"
dest: "{{ unifi_base_dir }}/{{ unifi_version }}/UniFi"
become: True
become_user: "{{ unifi_user }}"
delegate_to: "{{ inventory_hostname }}"
2018-07-12 21:02:27 +00:00
2019-01-09 21:11:03 +00:00
- name: Start service after restore process
systemd:
state: started
enabled: yes
name: unifi
become: True
become_user: root
2018-07-11 22:31:16 +00:00
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:
2019-01-09 21:11:03 +00:00
- name: Open ports in iptables
iptables_raw:
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 }}"
when: unifi_iptables_enabled
2018-07-11 20:37:44 +00:00
2019-01-09 21:11:03 +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
2018-07-08 21:02:55 +00:00
2019-01-09 21:11:03 +00:00
- 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
2019-01-09 21:11:03 +00:00
- name: Set current version to custom fact
template:
src: etc/ansible/facts.d/unifi.fact.j2
dest: /etc/ansible/facts.d/unifi.fact
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
2018-09-16 20:34:16 +00:00
become_user: root