xoxys.unifi/tasks/install.yml

94 lines
2.7 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-08 22:53:57 +00:00
when: unifi_current_version is version_compare(unifi_version, ">") or unifi_current_version is version_compare('0.0.0', "=")
2018-07-08 21:35:10 +00:00
2018-07-11 21:14:38 +00:00
# - block:
# - name: Remove data folder from new version
# file:
# path: "{{ unifi_base_dir }}/{{ unifi_current_version }}//UniFi/data"
# state: absent
2018-07-11 21:29:35 +00:00
#
# - name: Copy data folder from previews version
# copy:
# src: "{{ unifi_base_dir }}/{{ unifi_version }}//UniFi/data"
# dest: "{{ unifi_base_dir }}/{{ unifi_current_version }}//UniFi/data"
# remote_src: True
2018-07-11 21:14:38 +00:00
# become: True
# become_user: "{{ unifi_user }}"
# when:
2018-07-11 21:29:35 +00:00
# - unifi_current_version is version_compare(unifi_version, ">")
2018-07-11 21:14:38 +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:
name: "{{ item.flag }}"
state: present
2018-07-11 21:00:51 +00:00
rules: "-A {{ item.direction | upper }} -m state --state NEW -p {{ item.proto | lower }} --dport {{ item.port }} -j ACCEPT"
2018-07-11 20:44:09 +00:00
with_items: "{{ unifi_open_ports }}"
2018-07-11 20:57:06 +00:00
loop_control:
label: "{{ item.flag }}"
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-08 22:53:57 +00:00
when: unifi_current_version is version_compare(unifi_version, ">") or unifi_current_version is version_compare('0.0.0', "=")
2018-07-08 21:02:55 +00:00
become: True