From 391ea1663c5d9805187f44b2b3d51f8dcfe707ac Mon Sep 17 00:00:00 2001 From: Will Bradley Date: Tue, 14 Jun 2016 13:24:23 -0700 Subject: [PATCH] Changing from Ansbile Playbook to Galaxy Role --- .gitignore | 1 + README.md | 51 ++++++++++++++++--------- config.properties | 1 - defaults/main.yml | 2 + files/UniFi-unix-zip-goes-here | 0 handlers/main.yml | 2 + meta/main.yml | 15 ++++++++ tasks/main.yml | 44 +++++++++++++++++++++ templates/config.properties.j2 | 1 + unifi.init => templates/unifi.init.j2 | 4 +- unifi.play | 55 --------------------------- vars/main.yml | 10 +++++ 12 files changed, 111 insertions(+), 75 deletions(-) create mode 100644 .gitignore delete mode 100644 config.properties create mode 100644 defaults/main.yml create mode 100644 files/UniFi-unix-zip-goes-here create mode 100644 handlers/main.yml create mode 100644 meta/main.yml create mode 100644 tasks/main.yml create mode 100644 templates/config.properties.j2 rename unifi.init => templates/unifi.init.j2 (91%) delete mode 100644 unifi.play create mode 100644 vars/main.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4415cba --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +files/*.zip \ No newline at end of file diff --git a/README.md b/README.md index 94a43ea..d2f4c36 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,48 @@ -# unifi-controller-rhel +UniFi Controller for RedHat/Centos/etc +====================================== -## About +Ansible Galaxy role for installing UniFi Controller software for Ubiquiti Access Points on RHEL 6. -Anisble playbook for installing UniFi Controller software for Ubiquiti -Access Points on RHEL 6 +Forked from https://github.com/fukawi2/unifi-controller-rhel and modified to be an includable role via Galaxy instead of a playbook. -## Requirements +Requirements +------------ -You need the [EPEL Repository](https://fedoraproject.org/wiki/EPEL) from -Fedora Project enabled to be able to install the requirements (MongoDB etc): +- You need the [EPEL Repository](https://fedoraproject.org/wiki/EPEL) from Fedora Project enabled to be able to install the requirements (MongoDB etc) +- Ubiquiti's license does not allow redistribution of the software ZIP, so you must manually download the ZIP of the UniFi Controller software from the [Ubiquiti website](https://www.ubnt.com/download/unifi/) and save it to `files/UniFi.unix.zip`. The most recent tested version is "UniFi v5.0.6 Zip for DIY Unix/Linux" from 2016-06-01. -## Usage +Role Variables +-------------- -Ubiquiti's license does not allow redistribution of the software ZIP, so you -must manually download the ZIP of the UniFi Controller software from the -Ubiquiti website and save it to the same folder as the playbook as "UniFi.zip" +- **unifi_controller_rhel.ntp_server** (optional) sets your preferred NTP server for the UniFi APs to use -Optionally, update the playbook variable 'ntp_server' to point to your -preferred NTP server for the AP's to use. +Dependencies +------------ -The playbook will run against the "unifi_controllers" group in your Ansible -inventory: +n/a - ansible-playbook unifi.play +Example Playbook +---------------- -## Support + - hosts: your_unifi_controllers + sudo: yes + roles: + - zyphlar.unifi_controller_rhel + +License +------- + +BSD + +Support +------- There is none. Tested on CentOS 6 x86_64. Not tested on animals. Your results may vary. Discontinue use and see a doctor if rash occurs. + +Author Information +------------------ + +- [fukawi2](https://github.com/fukawi2) (Original) +- [zyphlar](https://github.com/zyphlar) (Ansible Galaxy version) diff --git a/config.properties b/config.properties deleted file mode 100644 index a56d72f..0000000 --- a/config.properties +++ /dev/null @@ -1 +0,0 @@ -config.ntp_server={{ ntp_server }} diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..f398bdc --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for unifi_controller_rhel diff --git a/files/UniFi-unix-zip-goes-here b/files/UniFi-unix-zip-goes-here new file mode 100644 index 0000000..e69de29 diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..34929a4 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for unifi_controller_rhel diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..5065912 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,15 @@ +--- +galaxy_info: + author: zyphlar + description: UniFi Controller for RedHat/Centos/etc + company: Zyphon LLC + license: license (MIT) + min_ansible_version: 1.2 + platforms: + - name: EL + versions: + - 6 + galaxy_tags: + - networking + - monitoring +dependencies: [] diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..01e218b --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,44 @@ +--- +# tasks file for unifi_controller_rhel + +- name: abort if os is not suitable + when: ansible_os_family != "RedHat" + fail: "msg={{ansible_os_family}} is not supported by this playbook" + +- name: install java and mongodb + when: ansible_os_family == "RedHat" + yum: name={{ item }} state=present + with_items: + - java-1.6.0-openjdk + - jakarta-commons-daemon-jsvc + - mongodb-server + +- name: no need for the standard mongod service + service: name=mongod enabled=no state=stopped + +- name: setup unifi group + group: name={{ unifi_controller_rhel.unifi_gid }} system=yes state=present + +- name: setup unifi user + user: name={{ unifi_controller_rhel.unifi_uid }} home={{ unifi_controller_rhel.unifi_prefix }}/UniFi createhome=no shell=/sbin/nologin system=yes state=present + +- name: copy unifi zipball to host + copy: src={{ unifi_controller_rhel.unifi_zip_file }} dest={{ unifi_controller_rhel.unifi_zip_dest }} + +- name: extract unifi + command: /usr/bin/unzip -o {{ unifi_controller_rhel.unifi_zip_dest }} -d {{ unifi_controller_rhel.unifi_prefix }} creates=/opt/UniFi + +- name: fix permissions + command: /bin/chown -R {{ unifi_controller_rhel.unifi_uid }}:{{ unifi_controller_rhel.unifi_gid }} {{ unifi_controller_rhel.unifi_prefix }}/UniFi + +- name: symlink mongod binary to where unifi path + file: src=/usr/bin/mongod dest={{ unifi_controller_rhel.unifi_prefix }}/UniFi/bin/mongod state=link + +- name: install custom config.properties + template: src=config.properties.j2 dest={{ unifi_controller_rhel.unifi_prefix }}/UniFi/data/config.properties owner={{ unifi_controller_rhel.unifi_uid }} group={{ unifi_controller_rhel.unifi_gid }} + +- name: install init script + template: src=unifi.init.j2 dest=/etc/init.d/unifi owner=root group=root mode=755 + +- name: start unifi service + service: name=unifi enabled=yes state=started diff --git a/templates/config.properties.j2 b/templates/config.properties.j2 new file mode 100644 index 0000000..c7ceb0c --- /dev/null +++ b/templates/config.properties.j2 @@ -0,0 +1 @@ +config.ntp_server={{ unifi_controller_rhel.ntp_server }} diff --git a/unifi.init b/templates/unifi.init.j2 similarity index 91% rename from unifi.init rename to templates/unifi.init.j2 index 769d1e2..ea3f697 100755 --- a/unifi.init +++ b/templates/unifi.init.j2 @@ -6,13 +6,13 @@ NAME="unifi" DESC="Ubiquiti UniFi Controller" -BASEDIR="{{unifi_prefix}}/UniFi" +BASEDIR="{{ unifi_controller_rhel.unifi_prefix }}/UniFi" MAINCLASS="com.ubnt.ace.Launcher" PIDFILE="/var/run/${NAME}/${NAME}.pid" PATH=/bin:/usr/bin:/sbin:/usr/sbin -JAVA_HOME="{{ java_home }}" +JAVA_HOME="{{ unifi_controller_rhel.java_home }}" # JSVC - for running java apps as services JSVC=`which jsvc` #JSVC_OPTS="-debug" diff --git a/unifi.play b/unifi.play deleted file mode 100644 index 6412905..0000000 --- a/unifi.play +++ /dev/null @@ -1,55 +0,0 @@ ---- - -- hosts: unifi_controllers - vars: - - unifi_zip_file: UniFi-2.4.6.zip - - unifi_zip_dest: /usr/local/src/UniFi-2.4.6.zip - - unifi_prefix: /opt - - unifi_uid: unifi - - unifi_gid: unifi - - ntp_server: pool.ntp.org - - java_home: /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64 - sudo: yes - tasks: - - - name: abort if os is not suitable - when: ansible_os_family != "RedHat" - fail: "msg={{ansible_os_family}} is not supported by this playbook" - - - name: install java and mongodb - when: ansible_os_family == "RedHat" - yum: name={{ item }} state=present - with_items: - - java-1.6.0-openjdk - - jakarta-commons-daemon-jsvc - - mongodb-server - - - name: no need for the standard mongod service - service: name=mongod enabled=no state=stopped - - - name: setup unifi group - group: name={{ unifi_gid }} system=yes state=present - - - name: setup unifi user - user: name={{ unifi_uid }} home={{ unifi_prefix }}/UniFi createhome=no shell=/sbin/nologin system=yes state=present - - - name: copy unifi zipball to host - copy: src={{ unifi_zip_file }} dest={{ unifi_zip_dest }} - - - name: extract unifi - command: /usr/bin/unzip -o {{ unifi_zip_dest }} -d {{ unifi_prefix }} creates=/opt/UniFi - - - name: fix permissions - command: /bin/chown -R {{ unifi_uid }}:{{ unifi_gid }} {{ unifi_prefix }}/UniFi - - - name: symlink mongod binary to where unifi path - file: src=/usr/bin/mongod dest={{ unifi_prefix }}/UniFi/bin/mongod state=link - - - name: install custom config.properties - template: src=config.properties dest={{ unifi_prefix }}/UniFi/data/config.properties owner={{ unifi_uid }} group={{ unifi_gid }} - - - name: install init script - template: src=unifi.init dest=/etc/init.d/unifi owner=root group=root mode=755 - - - name: start unifi service - service: name=unifi enabled=yes state=started diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..f1c1d89 --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,10 @@ +--- +# vars file for unifi_controller_rhel + +- unifi_controller_rhel.ntp_server: pool.ntp.org +- unifi_controller_rhel.unifi_zip_file: UniFi.unix.zip +- unifi_controller_rhel.unifi_zip_dest: /usr/local/src/UniFi-2.4.6.zip +- unifi_controller_rhel.unifi_prefix: /opt +- unifi_controller_rhel.unifi_uid: unifi +- unifi_controller_rhel.unifi_gid: unifi +- unifi_controller_rhel.java_home: /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64