Updating to a working state

This commit is contained in:
Will Bradley 2016-06-14 16:17:13 -07:00
parent 391ea1663c
commit 1edac06e03
6 changed files with 90 additions and 79 deletions

View File

@ -9,12 +9,13 @@ 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. - 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. If you are including this role via Galaxy, you may download this file to your playbook's `files` directory instead of this role's `files` directory; both will work.
Role Variables Role Variables
-------------- --------------
- **unifi_controller_rhel.ntp_server** (optional) sets your preferred NTP server for the UniFi APs to use - **unifi_controller_rhel_ntp_server** (optional) sets your preferred NTP server for the UniFi APs to use (default: `pool.ntp.org`)
- **unifi_controller_rhel_unifi_zip_file** (optional) sets the filename of the UniFi controller software on the Ansible system (default: `UniFi.unix.zip`)
Dependencies Dependencies
------------ ------------
@ -24,11 +25,24 @@ n/a
Example Playbook Example Playbook
---------------- ----------------
First, install this role via Galaxy by typing `sudo ansible-galaxy install zyphlar.unifi_controller_rhel`
Then create and run an Ansible playbook like this:
- hosts: your_unifi_controllers - hosts: your_unifi_controllers
sudo: yes become: true
roles: roles:
- zyphlar.unifi_controller_rhel - zyphlar.unifi_controller_rhel
Or, if you want to override some variables:
- hosts: your_unifi_controllers
become: true
roles:
- some_other_role
- role: zyphlar.unifi_controller_rhel
unifi_controller_rhel_unifi_zip_file: UniFi.unix.5.0.6.zip
License License
------- -------

View File

@ -3,7 +3,10 @@
- name: abort if os is not suitable - name: abort if os is not suitable
when: ansible_os_family != "RedHat" when: ansible_os_family != "RedHat"
fail: "msg={{ansible_os_family}} is not supported by this playbook" fail: msg="{{ansible_os_family}} is not supported by this playbook"
- name: create mongo repository
template: src=mongodb-org-3.2.repo.j2 dest=/etc/yum.repos.d/mongodb-org-3.2.repo owner=root group=root
- name: install java and mongodb - name: install java and mongodb
when: ansible_os_family == "RedHat" when: ansible_os_family == "RedHat"
@ -11,34 +14,37 @@
with_items: with_items:
- java-1.6.0-openjdk - java-1.6.0-openjdk
- jakarta-commons-daemon-jsvc - jakarta-commons-daemon-jsvc
- mongodb-server - mongodb-org
- name: no need for the standard mongod service - name: no need for the standard mongod service
service: name=mongod enabled=no state=stopped service: name=mongod enabled=no state=stopped
- name: setup unifi group - name: setup unifi group
group: name={{ unifi_controller_rhel.unifi_gid }} system=yes state=present group: name={{ unifi_controller_rhel_unifi_gid }} system=yes state=present
- name: setup unifi user - 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 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 - name: copy unifi zipball to host
copy: src={{ unifi_controller_rhel.unifi_zip_file }} dest={{ unifi_controller_rhel.unifi_zip_dest }} copy: src={{ unifi_controller_rhel_unifi_zip_file }} dest={{ unifi_controller_rhel_unifi_zip_dest }} force=no
- name: extract unifi - name: extract unifi
command: /usr/bin/unzip -o {{ unifi_controller_rhel.unifi_zip_dest }} -d {{ unifi_controller_rhel.unifi_prefix }} creates=/opt/UniFi command: /usr/bin/unzip -o {{ unifi_controller_rhel_unifi_zip_dest }} -d {{ unifi_controller_rhel_unifi_prefix }} creates={{ unifi_controller_rhel_unifi_prefix }}/UniFi
- name: create unifi data directory
file: dest={{ unifi_controller_rhel_unifi_prefix }}/UniFi/data state=directory
- name: fix permissions - name: fix permissions
command: /bin/chown -R {{ unifi_controller_rhel.unifi_uid }}:{{ unifi_controller_rhel.unifi_gid }} {{ unifi_controller_rhel.unifi_prefix }}/UniFi 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 - name: symlink mongod binary to where unifi path
file: src=/usr/bin/mongod dest={{ unifi_controller_rhel.unifi_prefix }}/UniFi/bin/mongod state=link file: src=/usr/bin/mongod dest={{ unifi_controller_rhel_unifi_prefix }}/UniFi/bin/mongod state=link
- name: install custom config.properties - 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 }} 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 - name: install init script
template: src=unifi.init.j2 dest=/etc/init.d/unifi owner=root group=root mode=755 template: src=unifi.init.j2 dest=/etc/init.d/UniFi owner=root group=root mode=755
- name: start unifi service - name: start unifi service
service: name=unifi enabled=yes state=started service: name=UniFi enabled=yes state=started

View File

@ -1 +1 @@
config.ntp_server={{ unifi_controller_rhel.ntp_server }} config.ntp_server={{ unifi_controller_rhel_ntp_server }}

View File

@ -0,0 +1,7 @@
{# Note: expected ansible_distribution is "Amazon" or "RedHat" to be compatible with yum repos listed here https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/ -#}
[mongodb-org-3.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/{{ ansible_distribution|lower }}/2013.03/mongodb-org/3.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc

View File

@ -1,68 +1,53 @@
#!/bin/bash #!/bin/bash
# chkconfig: 2345 95 20 # chkconfig: 2345 95 20
# description: UniFi system # description: UniFi system
# processname: unifi # processname: UniFi
NAME="unifi" ctrl_start()
DESC="Ubiquiti UniFi Controller" {
java -jar {{ unifi_controller_rhel_unifi_prefix }}/UniFi/lib/ace.jar start &
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="{{ unifi_controller_rhel.java_home }}"
# 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} \
-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_stop()
{
java -jar {{ unifi_controller_rhel_unifi_prefix }}/UniFi/lib/ace.jar stop &
} }
ctrl_restart() { ctrl_restart()
ctrl_stop {
sleep 3 ctrl_stop
ctrl_start sleep 1
ctrl_start
} }
case "$1" in 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 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

View File

@ -1,10 +1,9 @@
--- ---
# vars file for unifi_controller_rhel # vars file for unifi_controller_rhel
unifi_controller_rhel_ntp_server: pool.ntp.org
- unifi_controller_rhel.ntp_server: pool.ntp.org unifi_controller_rhel_unifi_zip_file: UniFi.unix.zip
- unifi_controller_rhel.unifi_zip_file: UniFi.unix.zip unifi_controller_rhel_unifi_zip_dest: /usr/local/src/UniFi.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_prefix: /opt unifi_controller_rhel_unifi_uid: unifi
- unifi_controller_rhel.unifi_uid: unifi unifi_controller_rhel_unifi_gid: 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
- unifi_controller_rhel.java_home: /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64