94 lines
2.4 KiB
YAML
94 lines
2.4 KiB
YAML
---
|
|
- name: Set current unifi version
|
|
set_fact:
|
|
unifi_current_version: "{{ (ansible_local.unifi | default (dict(version='0.0.0')))['version'] }}"
|
|
|
|
- debug:
|
|
msg: Current version is '{{ unifi_current_version }}'
|
|
|
|
- block:
|
|
- name: Install requirements
|
|
package:
|
|
name: "{{ item }}"
|
|
state: present
|
|
with_items:
|
|
- "java-{{ unifi_openjdk_version }}-openjdk"
|
|
- unzip
|
|
- wget
|
|
|
|
- name: Create group '{{ unifi_group }}'
|
|
group:
|
|
name: "{{ unifi_group }}"
|
|
state: present
|
|
|
|
- name: Create user '{{ unifi_user }}'
|
|
user:
|
|
name: "{{ unifi_user }}"
|
|
group: "{{ unifi_group }}"
|
|
|
|
- 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 }}"
|
|
- /etc/ansible/facts.d
|
|
become: True
|
|
|
|
- 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
|
|
|
|
- name: Setup unifi version '{{ unifi_version }}'
|
|
unarchive:
|
|
src: /tmp/UniFi.unix.zip
|
|
dest: "{{ unifi_base_dir }}/{{ unifi_version }}"
|
|
remote_src: yes
|
|
|
|
- name: Cleanup
|
|
file:
|
|
path: /tmp/UniFi.unix.zip
|
|
state: absent
|
|
become: True
|
|
become_user: "{{ unifi_user }}"
|
|
when: unifi_current_version is version_compare(unifi_version, ">") or unifi_current_version is version_compare('0.0.0', "=")
|
|
|
|
- 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 }}"
|
|
|
|
- block:
|
|
- 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
|
|
|
|
- name: Set current version to custom fact
|
|
template:
|
|
src: etc/ansible/fact.d/unifi.json.j2
|
|
dest: /etc/ansible/fact.d/unifi.json
|
|
when: unifi_current_version is version_compare(unifi_version, ">") or unifi_current_version is version_compare('0.0.0', "=")
|
|
become: True
|