From b2eb6ce7aa5a879f65ca5c886d8a526727e5d7ba Mon Sep 17 00:00:00 2001 From: Phillip Smith Date: Tue, 27 May 2014 11:33:22 +1000 Subject: [PATCH] initial commit --- README.md | 32 +++++++++++++++++++--- config.properties | 1 + unifi.init | 69 +++++++++++++++++++++++++++++++++++++++++++++++ unifi.play | 54 +++++++++++++++++++++++++++++++++++++ 4 files changed, 153 insertions(+), 3 deletions(-) create mode 100644 config.properties create mode 100755 unifi.init create mode 100644 unifi.play diff --git a/README.md b/README.md index 44a6f83..37bf2cb 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,30 @@ -unifi-controller-rhel -===================== +# unifi-controller-rhel -Anisble playbook for installing UniFi Controller for Ubiquiti Access Points on RHEL 6 +## About + +Anisble playbook for installing UniFi Controller software for Ubiquiti +Access Points on RHEL 6 + +## Requirements + +You need the EPEL Repository from Fedora Project enabled to be able to +install the requirements (MongoDB etc). + +## Usage + +You must 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" + +Optionally, update the playbook variable 'ntp_server' to point to your +preferred NTP server for the AP's to use. + +The playbook will run against the "unifi_controllers" group in your Ansible +inventory: + + ansible-playbook unifi.play + +## 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. diff --git a/config.properties b/config.properties new file mode 100644 index 0000000..a56d72f --- /dev/null +++ b/config.properties @@ -0,0 +1 @@ +config.ntp_server={{ ntp_server }} diff --git a/unifi.init b/unifi.init new file mode 100755 index 0000000..57b6b97 --- /dev/null +++ b/unifi.init @@ -0,0 +1,69 @@ +#!/bin/bash +# chkconfig: 2345 95 20 +# description: UniFi system +# processname: unifi + +NAME="unifi" +DESC="Ubiquiti UniFi Controller" + +BASEDIR="{{unifi_prefix}}/UniFi" +MAINCLASS="com.ubnt.ace.Launcher" + +PIDFILE="/var/run/${NAME}/${NAME}.pid" +PATH=/bin:/usr/bin:/sbin:/usr/sbin + +JAVA_HOME=/usr/lib/jvm/java-6-openjdk +# JSVC - for running java apps as services +JSVC=`which jsvc` +#JSVC_OPTS="-debug" +JSVC_OPTS="${JSVC_OPTS}\ + -home ${JAVA_HOME} \ + -cp /usr/share/java/commons-daemon.jar:${BASEDIR}/lib/ace.jar \ + -pidfile ${PIDFILE} \ + -procname ${NAME} \ + -outfile SYSLOG \ + -errfile SYSLOG \ + -Djava.awt.headless=true -Xmx1024M" + +# Source function library. +. /etc/init.d/functions + +[ -d /var/run/${NAME} ] || mkdir -p /var/run/${NAME} +cd ${BASEDIR} + +ctrl_start() { + ${JSVC} ${JSVC_OPTS} ${MAINCLASS} start +} + +ctrl_stop() { + ${JSVC} ${JSVC_OPTS} ${MAINCLASS} stop +} + +ctrl_restart() { + ctrl_stop + sleep 3 + ctrl_start +} + +case "$1" in +start) + echo -n "starting UniFi system ..." + ctrl_start + echo " service started" + ;; +stop) + echo -n "stopping UniFi system ..." + ctrl_stop + echo " service stopped" + ;; +restart) + echo -n "restarting UniFi system ..." + ctrl_restart + echo "service restarted" + ;; +*) + echo "usage: service unifi {start|stop|restart}" + ;; +esac + +exit 0 diff --git a/unifi.play b/unifi.play new file mode 100644 index 0000000..87fa5a6 --- /dev/null +++ b/unifi.play @@ -0,0 +1,54 @@ +--- + +- hosts: unifi_controllers + vars: + - unifi_zip_file: UniFi.zip + - unifi_zip_dest: /usr/local/src/UniFi.zip + - unifi_prefix: /opt + - unifi_uid: unifi + - unifi_gid: unifi + - ntp_server: pool.ntp.org + sudo: yes + tasks: + + - name: check os is ok + 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.7.0-openjdk + - jakarta-commons-daemon-jsvc + - mongodb-server + + - name: ensure mongod is running + service: name=mongod enabled=yes state=started + + - 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 -f -o {{ unifi_zip_dest }} -d {{ unifi_prefix }} + + - 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 + copy: 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