diff --git a/.travis.yml b/.travis.yml index 9eebea3..3e7c98e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,12 +3,12 @@ language: python python: "2.7" before_install: - # Make sure everything's up to date. + # Make sure everything's up to date. - sudo apt-get update -qq - sudo apt-get install -qq python-apt python-pycurl git python-pip install: - # Install Ansible. + # Install Ansible. - pip install ansible script: @@ -27,7 +27,6 @@ script: && (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1) - # 1st: check syntax - echo "***************************** SYNTAX CHECK test 2 (1) *****************************" - ansible-playbook -i local.ini test2.yml --syntax-check @@ -42,18 +41,30 @@ script: && (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1) + # 1st: check syntax + - echo "***************************** SYNTAX CHECK test 3 (1) *****************************" + - ansible-playbook -i local.ini test3.yml --syntax-check + # 2nd: Make sure we run the entire playbook + - echo "***************************** RUN PLAY test 3 (2) *****************************" + - ansible-playbook -i local.ini test3.yml --sudo -vvvv + # 3rd: Make sure our playbook is idempotent + - echo "***************************** Idempotence test test 3 (3) *****************************" + - > + ansible-playbook -i local.ini test3.yml --sudo -vvvv | tee ansible_output + | grep -q 'changed=0.*failed=0' + && (echo 'Idempotence test: pass' && exit 0) + || (echo 'Idempotence test: fail' && exit 1) after_failure: - - echo -e "######IdepotanceLog #######" + - echo "******IdepotanceLog *******" - sudo cat ansible_output - - echo -e "######Syslog#######" + - echo "******Syslog*******" - sudo cat /var/log/syslog - - echo -e "######NerveLog#######" + - echo "******NerveLog*******" - sudo cat /var/log/smartstack/nerve.log - - echo -e "######SerfLog#######" + - echo "******SerfLog*******" - sudo cat /var/log/smartstack/serf.log - - echo -e "######SyanpaseLog#######" + - echo "******SyanpaseLog*******" - sudo cat /var/log/smartstack/synapse.log - - echo -e "######AnsibleFacts#######" - - ansible -i 127.0.0.1, -m setup all -c local - + - echo "******AnsibleFacts*******" + - ansible -i 127.0.0.1, -m setup all -c local \ No newline at end of file diff --git a/defaults/main.yml b/defaults/main.yml index d9a0ac6..97a2d61 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -8,6 +8,12 @@ smartstack_env_variable : #smartstack_services_files : "service.yml" # set a filename here to include extra vars for nerve/synapse smartstack_base_log_dir : "/var/log/smartstack" +# Omnibus Options +smartstack_omnibus_install : False +smartstack_omnibus_url : "https://github.com/yetu/omnibus-smartstack/releases/download/0.0.1/smartstack_0.0.1-1_amd64.deb" +smartstack_omnibus_sha256 : "548fbc3a92ec951bc8b1c3b086f1a1731cd859b727fd5897b6d92013255721ea" +smartstack_omnibus_src : "/opt/smartstack/src" + #If you are using different stages such as dev,prod # you should set this tag # This tag will be appended at the end of the each service only if is set @@ -138,5 +144,6 @@ ip_fallback : False # if my match rules dont work just match the first IP ruby_install : False ruby_version : 2.1 - +# TODO: Remove me Left for backward compatibility +smartstack_git_install : False diff --git a/demo/Vagrantfile b/demo/Vagrantfile index ec58146..dc39ddc 100644 --- a/demo/Vagrantfile +++ b/demo/Vagrantfile @@ -5,13 +5,17 @@ Vagrant.configure("2") do |config| config.vm.box_url = "http://files.vagrantup.com/precise64.box" ## Number of nodes - nodes = 2 + nodes = 3 rangeofips = 149 (1..nodes).each do |n| vmip = "192.168.56.#{rangeofips + n.to_i}" name = "demo#{n}" ##Node Conf + config.vm.provider "virtualbox" do |v| + v.customize ["modifyvm", :id, "--cpus", "1", "--memory", "512"] + end + config.vm.define name do |cfg| cfg.vm.box = name cfg.vm.host_name = name @@ -26,7 +30,6 @@ Vagrant.configure("2") do |config| cfg.vm.provider "virtualbox" do |vb| vb.gui = false end - ##Ansible Provisioning cfg.vm.provision :ansible do |ansible| ansible.playbook = "vagrant-provision.yml" diff --git a/demo/defaults-var.yml b/demo/defaults-var.yml index 627f603..dca3a50 100644 --- a/demo/defaults-var.yml +++ b/demo/defaults-var.yml @@ -1,2 +1,56 @@ --- -## Just a place holder file \ No newline at end of file +## Just a place holder file +smartstack_services_files : "" +services_ports : + synapse : 3210 + nerve : 3211 + haproxy : 3212 + mysql : 3306 + superapp : 8000 + postgresql : 5432 + +services : + superapp: + synapse : + discovery : + method : "serf" + haproxy : + server_options : "check inter 10s fastinter 5s downinter 8s rise 3 fall 2" + listen : + - "mode tcp" + - "timeout connect 10s" + - "timeout client 1h" + - "timeout server 1h" + port : "{{ services_ports['superapp'] }}" + nerve: + port : "{{ services_ports['superapp'] }}" + reporter_type : "serf" + check_interval : 1 + checks: + - type : "http" + uri : "/health" + timeout : 1 + rise : 2 + fall : 3 + + postgresql: + synapse : + discovery : + method : "serf" + haproxy : + server_options : "check inter 10s fastinter 5s downinter 8s rise 3 fall 2" + listen : + - "mode tcp" + - "timeout connect 10s" + - "timeout client 1h" + - "timeout server 1h" + port : "{{ services_ports['postgresql'] }}" + nerve: + port : "{{ services_ports['postgresql'] }}" + reporter_type : "serf" + check_interval : 1 + checks: + - type : "tcp" + timeout : 5 + rise : 2 + fall : 2 \ No newline at end of file diff --git a/demo/demo1-var.yml b/demo/demo1-var.yml index f651037..2300e4d 100644 --- a/demo/demo1-var.yml +++ b/demo/demo1-var.yml @@ -1,7 +1,8 @@ --- nerve_install : True +nerve_selected_services : [ "postgresql", "superapp" ] synapse_install : False -nerve_selected_services : [ "postgresql" ] + serf_masters : [ "192.168.56.150", "192.168.56.151"] serf_bind : "{{service_ip}}" ip_match_enabled : True @@ -9,10 +10,15 @@ ip_match_rules : - regx : "192.168.56.*" reg_match : true -smartstack_services_files : "services.yml" +#smartstack_services_files : "services.yml" ##### #Since this is a demo we will make a list of packages to install packages_to_install : - "postgresql" + - "python-psycopg2" ### ruby_install : True + +## App config +color : "#D80000" +PS1 : '\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\[\e[0;31m\]\h\[\e[m\]:\w\$ ' \ No newline at end of file diff --git a/demo/demo2-var.yml b/demo/demo2-var.yml index 12a4ffd..de41098 100644 --- a/demo/demo2-var.yml +++ b/demo/demo2-var.yml @@ -1,18 +1,26 @@ --- -nerve_install : False +nerve_install : True +nerve_selected_services : [ "superapp" ] + synapse_install : True -synapse_selected_services : [ "postgresql" ] -serf_bind : "{{service_ip}}" +synapse_selected_services : [ "postgresql"] + serf_masters : [ "192.168.56.150", "192.168.56.151"] +serf_bind : "{{service_ip}}" ip_match_enabled : True ip_match_rules : - regx : "192.168.56.*" reg_match : true -smartstack_services_files : "services.yml" +#smartstack_services_files : "services.yml" ##### #Since this is a demo we will make a list of packages to install packages_to_install : - - "postgresql-client" + - "python-psycopg2" + ### -ruby_install : True \ No newline at end of file +ruby_install : True + +## +color : "#3300CC" +PS1 : '\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\[\e[1;34m\]\h\[\e[m\]:\w\$ ' \ No newline at end of file diff --git a/demo/demo3-var.yml b/demo/demo3-var.yml new file mode 100644 index 0000000..d077fc7 --- /dev/null +++ b/demo/demo3-var.yml @@ -0,0 +1,22 @@ +--- +nerve_install : False +synapse_install : True +synapse_selected_services : [ "superapp"] + +serf_masters : [ "192.168.56.150", "192.168.56.151"] +serf_bind : "{{service_ip}}" +ip_match_enabled : True +ip_match_rules : + - regx : "192.168.56.*" + reg_match : true + +#smartstack_services_files : "services.yml" +##### +#Since this is a demo we will make a list of packages to install +packages_to_install : + - "nginx" +### +ruby_install : True + +## App config +PS1 : '\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\[\e[0;32m\]\h\[\e[m\]:\w\$ ' \ No newline at end of file diff --git a/demo/nginx_default.conf b/demo/nginx_default.conf new file mode 100644 index 0000000..550750f --- /dev/null +++ b/demo/nginx_default.conf @@ -0,0 +1,9 @@ +server { + location / { + proxy_pass http://localhost:8000; + proxy_set_header Host $host; + } + location = /favicon.ico { + alias /var/www/media/images/favicon.X.ico; + } +} \ No newline at end of file diff --git a/demo/superapp.py.j2 b/demo/superapp.py.j2 new file mode 100644 index 0000000..9afac34 --- /dev/null +++ b/demo/superapp.py.j2 @@ -0,0 +1,47 @@ +#!/usr/bin/env python +from wsgiref.simple_server import make_server +import psycopg2 + +def build_response(): + conn_string = "host='localhost' dbname='superapp' user='superapp' password='superapp'" + print "Connecting to database\n ->%s" % (conn_string) + + try: + conn = psycopg2.connect(conn_string) + postgres_status = " RUNNING " + print "RUNNING to psql" + except: + postgres_status = " NOT RUNNING :(" + print not "RUNNING to psql" + + machine = "{{ inventory_hostname }}" + my_color = "{{ color }}" + + body = "" + body += "\n" + body += "" + body += "" + body += "A Small Hello" + body += "" + body += "" + body += "

Hi I am " + machine + "

" + body += "

Postgresql status " + postgres_status + "

" + body += "" + body += "" + return body + +def hello_world_app(environ, start_response): + machine = "{{ inventory_hostname }}" + status = '200 OK' # HTTP Status + headers = [('Content-type', 'text/html'), ('x-server',machine)] # HTTP Headers + start_response(status, headers) + + # The returned object is going to be printed + body = build_response() + return [body] + +httpd = make_server('', 8000, hello_world_app) +print "Serving on port 8000..." + +# Serve until process is killed +httpd.serve_forever() \ No newline at end of file diff --git a/demo/superapp.sh.j2 b/demo/superapp.sh.j2 new file mode 100644 index 0000000..39d5905 --- /dev/null +++ b/demo/superapp.sh.j2 @@ -0,0 +1,110 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: superapp +# Required-Start: $local_fs $remote_fs $network +# Required-Stop: $local_fs $remote_fs $network +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Generic Program +# Description: Generic Program is a generic program to do generic things with +### END INIT INFO + + +# Documentation available at +# http://refspecs.linuxfoundation.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptfunc.html +# Debian provides some extra functions though +. /lib/lsb/init-functions + + +DAEMON_NAME="superapp" +DAEMON_USER="{{ superapp_user }}" +DAEMON_PATH="{{ superapp_bin }}" +DAEMON_OPTS="{{ superapp_opts }}" +DAEMON_PWD="{{ superapp_pwd }}" +DAEMON_DESC=$(get_lsb_header_val $0 "Short-Description") +DAEMON_PID="/var/run/${DAEMON_NAME}.pid" +DAEMON_NICE=0 +DAEMON_LOG='/var/log/generic-prog' + +[ -r "/etc/default/${DAEMON_NAME}" ] && . "/etc/default/${DAEMON_NAME}" + +do_start() { + local result + + pidofproc -p "${DAEMON_PID}" "${DAEMON_PATH}" > /dev/null + if [ $? -eq 0 ]; then + log_warning_msg "${DAEMON_NAME} is already started" + result=0 + else + log_daemon_msg "Starting ${DAEMON_DESC}" "${DAEMON_NAME}" + touch "${DAEMON_LOG}" + chown $DAEMON_USER "${DAEMON_LOG}" + chmod u+rw "${DAEMON_LOG}" + if [ -z "${DAEMON_USER}" ]; then + start-stop-daemon --start --quiet --oknodo --background \ + --nicelevel $DAEMON_NICE \ + --chdir "${DAEMON_PWD}" \ + --pidfile "${DAEMON_PID}" --make-pidfile \ + --exec "${DAEMON_PATH}" -- $DAEMON_OPTS + result=$? + else + start-stop-daemon --start --quiet --oknodo --background \ + --nicelevel $DAEMON_NICE \ + --chdir "${DAEMON_PWD}" \ + --pidfile "${DAEMON_PID}" --make-pidfile \ + --chuid "${DAEMON_USER}" \ + --exec "${DAEMON_PATH}" -- $DAEMON_OPTS + result=$? + fi + log_end_msg $result + fi + return $result +} + +do_stop() { + local result + + pidofproc -p "${DAEMON_PID}" "${DAEMON_PATH}" > /dev/null + if [ $? -ne 0 ]; then + log_warning_msg "${DAEMON_NAME} is not started" + result=0 + else + log_daemon_msg "Stopping ${DAEMON_DESC}" "${DAEMON_NAME}" + killproc -p "${DAEMON_PID}" "${DAEMON_PATH}" + result=$? + log_end_msg $result + rm "${DAEMON_PID}" + fi + return $result +} + +do_restart() { + local result + do_stop + result=$? + if [ $result = 0 ]; then + do_start + result=$? + fi + return $result +} + +do_status() { + local result + status_of_proc -p "${DAEMON_PID}" "${DAEMON_PATH}" "${DAEMON_NAME}" + result=$? + return $result +} + +do_usage() { + echo $"Usage: $0 {start | stop | restart | status}" + exit 1 +} + +case "$1" in +start) do_start; exit $? ;; +stop) do_stop; exit $? ;; +restart) do_restart; exit $? ;; +status) do_status; exit $? ;; +*) do_usage; exit 1 ;; +esac \ No newline at end of file diff --git a/demo/vagrant-provision.yml b/demo/vagrant-provision.yml index 90c7712..9c44153 100644 --- a/demo/vagrant-provision.yml +++ b/demo/vagrant-provision.yml @@ -8,16 +8,26 @@ sudo: True vars_files: - "{{inventory_hostname}}-var.yml" + - "defaults-var.yml" ## If you dont want the run to fail if file does not exisit # - [ "{{inventory_hostname}}-var.yml", "defaults-var.yml" ] vars: - localuser: "{{ lookup('ENV','USER') }}" + superapp_user : "{{ lookup('ENV','USER') }}" + superapp_pwd : "/home/{{superapp_user}}" + superapp_bin : "/usr/bin/python" + superapp_opts : "superapp.py" + localuser : "{{ lookup('ENV','USER') }}" pre_tasks: + + - name: Install git + apt: + name="git" + - name: Create your local user user: name="{{localuser}}" - home="/home/{{localuser}}" + home="{{superapp_pwd}}" shell="/bin/bash" append="true" group="admin" @@ -30,30 +40,82 @@ manage_dir=yes ignore_errors: yes + - name : Change PS1 + lineinfile: + dest="{{superapp_pwd}}/.bashrc" + insertafter="EOF" + line="export PS1=\"{{ PS1 }}\"" + - name: Update apt cache apt: update_cache=yes + - name: Install superapp + template: + src="superapp.py.j2" + dest="{{superapp_pwd}}/superapp.py" + when: inventory_hostname == "demo1" or inventory_hostname == "demo2" + + - name: Install superapp service + template: + src="superapp.sh.j2" + dest="/etc/init.d/superapp" + mode=0755 + when: inventory_hostname == "demo1" or inventory_hostname == "demo2" + + - name: Enable superapp service + service: + name=superapp + state=restarted + when: inventory_hostname == "demo1" or inventory_hostname == "demo2" + + - name: Enable superapp service + service: + name=nginx + state=started + when: inventory_hostname == "demo3" + - name: Install demo packages apt: - name="{{item}}" + name="{{item}}" with_items: packages_to_install when : packages_to_install is defined - - name : postgresql + - name : Configure postgresql lineinfile: dest=/etc/postgresql/9.1/main/postgresql.conf - regexp='^listen_addresses' + regexp='^listen_addresses' line="listen_addresses = '*'" register: postgresql_conf when: "'postgresql' in packages_to_install" - - name : postgresql + - name : Configure postgresql hba.conf + lineinfile: + dest=/etc/postgresql/9.1/main/pg_hba.conf + regexp='^host all all" 0.0.0.0/0 md5' + line="host all all 0.0.0.0/0 md5" + when: "'postgresql' in packages_to_install" + + - name : Service postgresql service: name=postgresql state=restarted register: postgresql_conf when: "'postgresql' in packages_to_install and postgresql_conf | changed" + - name: Create postgresql db + postgresql_db: + name=superapp + sudo_user: postgres + when: "'postgresql' in packages_to_install" + + - name : Create postgresql user + postgresql_user: + db=superapp + name=superapp + password=superapp + sudo_user: postgres + when: "'postgresql' in packages_to_install" + roles : - ansible-smartstack \ No newline at end of file diff --git a/tasks/common.yml b/tasks/common.yml index 43bea2e..4a8bdb8 100644 --- a/tasks/common.yml +++ b/tasks/common.yml @@ -1,16 +1,16 @@ --- - name : common | Create smartstack user user : - name="{{smartstack_user}}" + name="{{smartstack_user}}" shell="/sbin/nologin" home="{{smartstack_home}}" - createhome="yes" - + createhome="yes" + + # TODO: Remove me Left for backward compatibility - name: common | Install git apt: - name="{{item}}" - with_items: - - git + name="git" + when: smartstack_git_install - name: common | Create base log directory file: diff --git a/tasks/ip_match.yml b/tasks/ip_match.yml index 5c2ff55..60ee06d 100644 --- a/tasks/ip_match.yml +++ b/tasks/ip_match.yml @@ -14,7 +14,7 @@ set_fact: service_ip="{{server_ips[0]}}" when: service_ip is not defined or service_ip == "" and ip_fallback - + - name: ip_match | Extract IP (3) Failed fail: msg="Could not set IP in {{server_ips}} that match rules. Please check your rules." when: service_ip is not defined or service_ip == "" diff --git a/tasks/main.yml b/tasks/main.yml index e6ee6b5..1927e36 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -14,6 +14,10 @@ - include : serf.yml tags: [ nerve, synapse, serf ] +- include : omnibus.yml + when: smartstack_omnibus_install + tags: [ nerve, synapse ] + - include : nerve.yml when: nerve_install tags: [ nerve ] diff --git a/tasks/nerve.yml b/tasks/nerve.yml index 0a866c8..ff54414 100644 --- a/tasks/nerve.yml +++ b/tasks/nerve.yml @@ -1,13 +1,22 @@ --- # tasks file for ansible-smartstack -- name: nerve | Get nerve from git +- name: nerv | Create synapse directories + file: + path="{{ nerve_home }}" + owner="{{ smartstack_user }}" + group="{{ smartstack_user }}" + mode=0755 + state=directory + +- name: nerve | Get nerve from gi git: repo="{{nerve_repository}}" dest="{{nerve_install_dir}}" force="no" version="{{nerve_reference}}" accept_hostkey=true + when: not smartstack_omnibus_install sudo_user: "{{smartstack_user}}" - name: nerve | Install nerve @@ -17,19 +26,20 @@ environment: smartstack_env_variable register: nerve_bundle_install changed_when: nerve_bundle_install.stdout.find('Installing') != -1 + when: not smartstack_omnibus_install sudo_user: "{{smartstack_user}}" #Maybe include in common only rather in synapse and nerve - name: nerve | Include services variable file include_vars: "{{smartstack_services_files}}" - when: smartstack_services_files is defined + when: smartstack_services_files is defined and smartstack_services_files - name: nerve | Deploy configuration file template: src=nerve/nerve_config.json.j2 dest="{{nerve_home}}/config.json" mode=0640 - owner="{{smartstack_user}}" + owner="{{smartstack_user}}" group="{{smartstack_user}}" notify: restart nerve @@ -54,4 +64,4 @@ service: name=nerve state=started - enabled=true \ No newline at end of file + enabled=true \ No newline at end of file diff --git a/tasks/omnibus.yml b/tasks/omnibus.yml new file mode 100644 index 0000000..df24f94 --- /dev/null +++ b/tasks/omnibus.yml @@ -0,0 +1,28 @@ +--- + +- name: omnibus | Create base source directory + file: + path="{{ smartstack_omnibus_src }}" + owner="{{ smartstack_user }}" + group="{{ smartstack_user }}" + mode=0755 + state=directory + +- name: omnibus | Get binary + get_url: + url="{{ smartstack_omnibus_url }}" + dest="{{ smartstack_omnibus_src }}/{{ omnibus_packagename | default(smartstack_omnibus_url | basename) }}" + sha256sum="{{ smartstack_omnibus_sha256 | default(omit) }}" + register: omnibus_download + + # ubuntu specific +- name: omnibus | Check if smartstack is installed + command: dpkg-query -W smartstack + register: omnibus_smartstack_check_deb + failed_when: omnibus_smartstack_check_deb.rc > 1 + changed_when: omnibus_smartstack_check_deb.rc == 1 + +- name: omnibus | Install omnibus deb + apt: + deb="{{ smartstack_omnibus_src }}/{{ omnibus_packagename | default(smartstack_omnibus_url | basename) }}" + when: omnibus_smartstack_check_deb.rc == 1 \ No newline at end of file diff --git a/tasks/serf.yml b/tasks/serf.yml index 3072b88..2fc4b8a 100644 --- a/tasks/serf.yml +++ b/tasks/serf.yml @@ -18,11 +18,11 @@ dest="{{serf_destination}}" mode=0750 owner="{{smartstack_user}}" - group="{{smartstack_user}}" + group="{{smartstack_user}}" - name: serf | Link the serf the installed version file: - src="{{serf_destination}}" + src="{{serf_destination}}" dest="/usr/bin/serf" state="link" @@ -32,9 +32,9 @@ copy: content='{{ serf_default_config | to_nice_json }}' dest="{{serf_config_file}}" - owner="{{smartstack_user}}" - group="{{smartstack_user}}" - mode=0755 + owner="{{smartstack_user}}" + group="{{smartstack_user}}" + mode=0755 notify: restart serf - name: serf | Deploy start script @@ -58,6 +58,6 @@ service: name=serf state=started - enabled=true + enabled=true diff --git a/tasks/synapse.yml b/tasks/synapse.yml index 9885ce4..06dd1b3 100644 --- a/tasks/synapse.yml +++ b/tasks/synapse.yml @@ -5,9 +5,9 @@ - name: synapse | Create synapse directories file: - path="{{synapse_home}}" - owner="{{smartstack_user}}" - group="{{smartstack_user}}" + path="{{ synapse_home }}" + owner="{{ smartstack_user }}" + group="{{ smartstack_user }}" mode=0755 state=directory @@ -26,6 +26,7 @@ force="no" version="{{synapse_reference}}" accept_hostkey=true + when: not smartstack_omnibus_install sudo_user: "{{smartstack_user}}" - name: synapse | Install synapse @@ -34,20 +35,21 @@ chdir: "{{synapse_install_dir}}" environment: smartstack_env_variable register: synapse_bundle_install - changed_when: synapse_bundle_install.stdout.find('Installing') != -1 + changed_when: synapse_bundle_install.stdout.find('Installing') != -1 + when: not smartstack_omnibus_install sudo_user: "{{smartstack_user}}" -#Maybe include in common only rather in synapse and nerve + #Maybe include in common only rather in synapse and nerve - name: synapse | Include services variable file include_vars: "{{smartstack_services_files}}" - when: smartstack_services_files is defined + when: smartstack_services_files is defined and smartstack_services_files - name: synapse | Deploy configuration file template: src=synapse/synapse_config.json.j2 dest="{{synapse_home}}/config.json" mode=0640 - owner="{{smartstack_user}}" + owner="{{smartstack_user}}" group="{{smartstack_user}}" notify: restart synapse @@ -72,5 +74,5 @@ service: name=synapse state=started - enabled=true + enabled=true diff --git a/templates/nerve/nerve_init.sh.j2 b/templates/nerve/nerve_init.sh.j2 index 33252d7..008f83c 100644 --- a/templates/nerve/nerve_init.sh.j2 +++ b/templates/nerve/nerve_init.sh.j2 @@ -5,11 +5,11 @@ DESC="nerve-service" RUN_AS_USER="{{smartstack_user}}" RUN_AS_GROUP="{{smartstack_user}}" -BASE_DIR="{{nerve_install_dir}}" +BASE_DIR="{{ nerve_home }}" GREP_NAME="bin/nerve" -ExecFile="{{nerve_home}}/nerve_start.sh" +ExecFile="{{ nerve_home }}/nerve_start.sh" STOPCMD="kill -9" diff --git a/templates/nerve/nerve_start.sh.j2 b/templates/nerve/nerve_start.sh.j2 index 06c4b83..ff81fa2 100644 --- a/templates/nerve/nerve_start.sh.j2 +++ b/templates/nerve/nerve_start.sh.j2 @@ -1,4 +1,8 @@ #!/bin/bash -cd {{nerve_install_dir}} -export GEM_HOME={{smartstack_env_variable.GEM_HOME}} -exec bundle exec ./bin/nerve --config {{nerve_home}}/config.json >> {{nerve_log_file}} 2>&1 \ No newline at end of file +{% if smartstack_omnibus_install %} +/opt/smartstack/bin/nerve --config {{nerve_home}}/config.json >> {{nerve_log_file}} 2>&1 +{% else %} +cd {{ nerve_install_dir }} +export GEM_HOME="{{ smartstack_env_variable.GEM_HOME }}" +exec bundle exec ./bin/nerve --config {{nerve_home}}/config.json >> {{nerve_log_file}} 2>&1 +{% endif %} \ No newline at end of file diff --git a/templates/synapse/synapse_init.sh.j2 b/templates/synapse/synapse_init.sh.j2 index 3c1fdc9..92c14a0 100644 --- a/templates/synapse/synapse_init.sh.j2 +++ b/templates/synapse/synapse_init.sh.j2 @@ -5,7 +5,7 @@ DESC="synapse-service" RUN_AS_USER="{{smartstack_user}}" RUN_AS_GROUP="{{smartstack_user}}" -BASE_DIR="{{synapse_install_dir}}" +BASE_DIR="{{ synapse_home }}" GREP_NAME="bin/synapse" diff --git a/templates/synapse/synapse_start.sh.j2 b/templates/synapse/synapse_start.sh.j2 index 4a3f0b1..b5c024a 100644 --- a/templates/synapse/synapse_start.sh.j2 +++ b/templates/synapse/synapse_start.sh.j2 @@ -1,4 +1,8 @@ #!/bin/bash +{% if smartstack_omnibus_install %} +/opt/smartstack/bin/synapse --config {{ synapse_home}}/config.json >> {{synapse_log_file}} 2>&1 +{% else %} cd {{synapse_install_dir}} export GEM_HOME={{smartstack_env_variable.GEM_HOME}} -exec bundle exec ./bin/synapse --config {{synapse_home}}/config.json >> {{synapse_log_file}} 2>&1 \ No newline at end of file +exec bundle exec ./bin/synapse --config {{synapse_home}}/config.json >> {{synapse_log_file}} 2>&1 +{% endif %} \ No newline at end of file diff --git a/tests/run_vagrant_kitchen.sh b/tests/run_vagrant_kitchen.sh old mode 100755 new mode 100644 diff --git a/tests/test1.yml b/tests/test1.yml index 027a4f7..ade91cc 100644 --- a/tests/test1.yml +++ b/tests/test1.yml @@ -1,19 +1,10 @@ --- -# -# This playbook deploys your keys to the vagrant -# - name: Provision my keys hosts: all sudo: True vars_files: - "test1_var.yml" - - pre_tasks: - - name: superservice - template: - src="./superservice.j2" - dest="/etc/init.d/superservice" - mode="0755" + roles : - ansible-smartstack \ No newline at end of file diff --git a/tests/test1_var.yml b/tests/test1_var.yml index bd4a247..69e3946 100644 --- a/tests/test1_var.yml +++ b/tests/test1_var.yml @@ -5,13 +5,107 @@ synapse_install : True synapse_selected_services : [ "postgresql" ] serf_masters : [ "127.0.0.1" ] serf_bind : "0.0.0.0" +smartstack_omnibus_install : True +ruby_install : False ip_match_enabled : True ip_fallback : True ip_match_rules : - regx : "192.168.*" reg_match : true -smartstack_services_files : "services.yml" -packages_to_install : - - "postgresql" -ruby_install : True + +services_ports : + synapse : 3210 + nerve : 3211 + haproxy : 3212 + mysql : 3306 + sqlslave : 3402 + memcache : 3403 + postgresql : 5432 + +services_ports_test : + synapse : 10000 + nerve : 9999 + +services : + superservice: + synapse : + discovery : + method : "serf" + haproxy : + server_options : "check inter 10s fastinter 5s downinter 8s rise 3 fall 2" + listen : + - "mode tcp" + - "timeout connect 10s" + - "timeout client 1h" + - "timeout server 1h" + port : "{{ services_ports_test['synapse'] }}" + nerve: + port : "{{ services_ports['nerve'] }}" + reporter_type : "serf" + check_interval : 3 + checks: + - type : "tcp" + timeout : 5 + rise : 2 + fall : 2 + memcache: + synapse : + discovery : + method : "serf" + haproxy : + server_options : "check inter 1s rise 1 fall 1" + listen : + - "mode tcp" + port : "{{ services_ports.memcache }}" + nerve : + port : "{{ services_ports.memcache }}" + reporter_type : "serf" + check_interval : 1 + checks: + - type : "tcp" + timeout : 1 + rise : 2 + fall : 3 + postgresql: + synapse : + discovery : + method : "serf" + haproxy : + server_options : "check inter 10s fastinter 5s downinter 8s rise 3 fall 2" + listen : + - "mode tcp" + - "timeout connect 10s" + - "timeout client 1h" + - "timeout server 1h" + port : "{{ services_ports['postgresql'] }}" + nerve: + port : "{{ services_ports['postgresql'] }}" + reporter_type : "serf" + check_interval : 3 + checks: + - type : "tcp" + timeout : 5 + rise : 2 + fall : 2 + sqlslave: + synapse : + discovery : + method : "serf" + haproxy : + server_options : "check inter 10s fastinter 5s downinter 8s rise 3 fall 2" + listen : + - "mode tcp" + - "timeout connect 10s" + - "timeout client 1h" + - "timeout server 1h" + port : "{{ services_ports.sqlslave }}" + nerve: + port : "{{ services_ports.sqlslave }}" + reporter_type : "serf" + check_interval : 3 + checks: + - type : "tcp" + timeout : 5 + rise : 2 + fall : 2 diff --git a/tests/test2.yml b/tests/test2.yml index 8eccc5f..e81b788 100644 --- a/tests/test2.yml +++ b/tests/test2.yml @@ -1,21 +1,31 @@ --- -# -# This playbook deploys your keys to the vagrant -# - name: Provision my keys hosts: all sudo: True vars_files: - "test2_var.yml" - + pre_tasks: - + + - name: Check if omibus was installed before + stat: + path=/opt/smartstack/bin/ + register: p + + - name: Stop Nerve and synapse + service: + name="{{ item }}" + state="stopped" + with_items: + - "synapse" + - "nerve" + when: p.stat.exists is defined and not p.stat.exists + - name: superservice template: src="./superservice.j2" dest="/etc/init.d/superservice" mode="0755" - roles : - ansible-smartstack \ No newline at end of file diff --git a/tests/test2_var.yml b/tests/test2_var.yml index f3277e4..bd4a247 100644 --- a/tests/test2_var.yml +++ b/tests/test2_var.yml @@ -11,99 +11,7 @@ ip_match_rules : - regx : "192.168.*" reg_match : true - -services_ports : - synapse : 3210 - nerve : 3211 - haproxy : 3212 - mysql : 3306 - sqlslave : 3402 - memcache : 3403 - postgresql : 5432 - -services_ports_test : - synapse : 10000 - nerve : 9999 - -services : - superservice: - synapse : - discovery : - method : "serf" - haproxy : - server_options : "check inter 10s fastinter 5s downinter 8s rise 3 fall 2" - listen : - - "mode tcp" - - "timeout connect 10s" - - "timeout client 1h" - - "timeout server 1h" - port : "{{ services_ports_test['synapse'] }}" - nerve: - port : "{{ services_ports['nerve'] }}" - reporter_type : "serf" - check_interval : 3 - checks: - - type : "tcp" - timeout : 5 - rise : 2 - fall : 2 - memcache: - synapse : - discovery : - method : "serf" - haproxy : - server_options : "check inter 1s rise 1 fall 1" - listen : - - "mode tcp" - port : "{{ services_ports.memcache }}" - nerve : - port : "{{ services_ports.memcache }}" - reporter_type : "serf" - check_interval : 1 - checks: - - type : "tcp" - timeout : 1 - rise : 2 - fall : 3 - postgresql: - synapse : - discovery : - method : "serf" - haproxy : - server_options : "check inter 10s fastinter 5s downinter 8s rise 3 fall 2" - listen : - - "mode tcp" - - "timeout connect 10s" - - "timeout client 1h" - - "timeout server 1h" - port : "{{ services_ports['postgresql'] }}" - nerve: - port : "{{ services_ports['postgresql'] }}" - reporter_type : "serf" - check_interval : 3 - checks: - - type : "tcp" - timeout : 5 - rise : 2 - fall : 2 - sqlslave: - synapse : - discovery : - method : "serf" - haproxy : - server_options : "check inter 10s fastinter 5s downinter 8s rise 3 fall 2" - listen : - - "mode tcp" - - "timeout connect 10s" - - "timeout client 1h" - - "timeout server 1h" - port : "{{ services_ports.sqlslave }}" - nerve: - port : "{{ services_ports.sqlslave }}" - reporter_type : "serf" - check_interval : 3 - checks: - - type : "tcp" - timeout : 5 - rise : 2 - fall : 2 +smartstack_services_files : "services.yml" +packages_to_install : + - "postgresql" +ruby_install : True diff --git a/tests/test3.yml b/tests/test3.yml new file mode 100644 index 0000000..9786002 --- /dev/null +++ b/tests/test3.yml @@ -0,0 +1,34 @@ +--- +# +# This playbook deploys your keys to the vagrant +# + +- name: Provision my keys + hosts: all + sudo: True + vars_files: + - "test2_var.yml" + + pre_tasks: + - name: Check if omibus was installed before + stat: + path=/opt/smartstack/bin/ + register: p + + - name: Stop Nerve and synapse + service: + name="{{ item }}" + state="stopped" + with_items: + - "synapse" + - "nerve" + when: p.stat.exists is defined and not p.stat.exists + + - name: superservice + template: + src="./superservice.j2" + dest="/etc/init.d/superservice" + mode="0755" + + roles : + - ansible-smartstack \ No newline at end of file diff --git a/tests/test3_var.yml b/tests/test3_var.yml new file mode 100644 index 0000000..f3277e4 --- /dev/null +++ b/tests/test3_var.yml @@ -0,0 +1,109 @@ +--- +nerve_install : True +nerve_selected_services : [ "postgresql" ] +synapse_install : True +synapse_selected_services : [ "postgresql" ] +serf_masters : [ "127.0.0.1" ] +serf_bind : "0.0.0.0" +ip_match_enabled : True +ip_fallback : True +ip_match_rules : + - regx : "192.168.*" + reg_match : true + + +services_ports : + synapse : 3210 + nerve : 3211 + haproxy : 3212 + mysql : 3306 + sqlslave : 3402 + memcache : 3403 + postgresql : 5432 + +services_ports_test : + synapse : 10000 + nerve : 9999 + +services : + superservice: + synapse : + discovery : + method : "serf" + haproxy : + server_options : "check inter 10s fastinter 5s downinter 8s rise 3 fall 2" + listen : + - "mode tcp" + - "timeout connect 10s" + - "timeout client 1h" + - "timeout server 1h" + port : "{{ services_ports_test['synapse'] }}" + nerve: + port : "{{ services_ports['nerve'] }}" + reporter_type : "serf" + check_interval : 3 + checks: + - type : "tcp" + timeout : 5 + rise : 2 + fall : 2 + memcache: + synapse : + discovery : + method : "serf" + haproxy : + server_options : "check inter 1s rise 1 fall 1" + listen : + - "mode tcp" + port : "{{ services_ports.memcache }}" + nerve : + port : "{{ services_ports.memcache }}" + reporter_type : "serf" + check_interval : 1 + checks: + - type : "tcp" + timeout : 1 + rise : 2 + fall : 3 + postgresql: + synapse : + discovery : + method : "serf" + haproxy : + server_options : "check inter 10s fastinter 5s downinter 8s rise 3 fall 2" + listen : + - "mode tcp" + - "timeout connect 10s" + - "timeout client 1h" + - "timeout server 1h" + port : "{{ services_ports['postgresql'] }}" + nerve: + port : "{{ services_ports['postgresql'] }}" + reporter_type : "serf" + check_interval : 3 + checks: + - type : "tcp" + timeout : 5 + rise : 2 + fall : 2 + sqlslave: + synapse : + discovery : + method : "serf" + haproxy : + server_options : "check inter 10s fastinter 5s downinter 8s rise 3 fall 2" + listen : + - "mode tcp" + - "timeout connect 10s" + - "timeout client 1h" + - "timeout server 1h" + port : "{{ services_ports.sqlslave }}" + nerve: + port : "{{ services_ports.sqlslave }}" + reporter_type : "serf" + check_interval : 3 + checks: + - type : "tcp" + timeout : 5 + rise : 2 + fall : 2