From f04cb0e811899f0cef2308459fb18b12a7661429 Mon Sep 17 00:00:00 2001 From: Adham Helal Date: Mon, 15 Jun 2015 23:09:40 +0200 Subject: [PATCH 1/9] Omnibus support --- .travis.yml | 33 +++++--- defaults/main.yml | 6 ++ tasks/common.yml | 6 +- tasks/ip_match.yml | 2 +- tasks/main.yml | 4 + tasks/nerve.yml | 6 +- tasks/omnibus.yml | 28 +++++++ tasks/serf.yml | 12 +-- tasks/synapse.yml | 10 ++- templates/nerve/nerve_start.sh.j2 | 10 ++- templates/synapse/synapse_start.sh.j2 | 6 +- tests/test1.yml | 5 +- tests/test2.yml | 4 +- tests/test3.yml | 26 ++++++ tests/test3_var.yml | 110 ++++++++++++++++++++++++++ 15 files changed, 231 insertions(+), 37 deletions(-) create mode 100644 tasks/omnibus.yml create mode 100644 tests/test3.yml create mode 100644 tests/test3_var.yml 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..2322170 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_omnibis_install : False +smartstack_omnibis_url : "https://github.com/yetu/omnibus-smartstack/releases/download/0.0.1/smartstack_0.0.1-1_amd64.deb" +smartstack_omnibis_sha256 : "548fbc3a92ec951bc8b1c3b086f1a1731cd859b727fd5897b6d92013255721ea" +smartstack_omnibis_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 diff --git a/tasks/common.yml b/tasks/common.yml index 43bea2e..46fcc9d 100644 --- a/tasks/common.yml +++ b/tasks/common.yml @@ -1,11 +1,11 @@ --- - name : common | Create smartstack user user : - name="{{smartstack_user}}" + name="{{smartstack_user}}" shell="/sbin/nologin" home="{{smartstack_home}}" - createhome="yes" - + createhome="yes" + - name: common | Install git apt: name="{{item}}" 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..0786dfd 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_omnibis_install + tags: [ nerve, synapse ] + - include : nerve.yml when: nerve_install tags: [ nerve ] diff --git a/tasks/nerve.yml b/tasks/nerve.yml index 0a866c8..49599be 100644 --- a/tasks/nerve.yml +++ b/tasks/nerve.yml @@ -8,6 +8,7 @@ force="no" version="{{nerve_reference}}" accept_hostkey=true + when: not smartstack_omnibis_install sudo_user: "{{smartstack_user}}" - name: nerve | Install nerve @@ -17,6 +18,7 @@ environment: smartstack_env_variable register: nerve_bundle_install changed_when: nerve_bundle_install.stdout.find('Installing') != -1 + when: not smartstack_omnibis_install sudo_user: "{{smartstack_user}}" #Maybe include in common only rather in synapse and nerve @@ -29,7 +31,7 @@ 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 +56,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..75e26db --- /dev/null +++ b/tasks/omnibus.yml @@ -0,0 +1,28 @@ +--- + +- name: omnibus | Create base source directory + file: + path="{{ smartstack_omnibis_src }}" + owner="{{ smartstack_user }}" + group="{{ smartstack_user }}" + mode=0755 + state=directory + +- name: omnibus | Get binary + get_url: + url="{{ smartstack_omnibis_url }}" + dest="{{ smartstack_omnibis_src }}" + sha256sum="{{ smartstack_omnibis_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_omnibis_src }}/{{ omnibus_packagename |default(smartstack_omnibis_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..4d6b453 100644 --- a/tasks/synapse.yml +++ b/tasks/synapse.yml @@ -26,6 +26,7 @@ force="no" version="{{synapse_reference}}" accept_hostkey=true + when: not smartstack_omnibis_install sudo_user: "{{smartstack_user}}" - name: synapse | Install synapse @@ -34,10 +35,11 @@ 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_omnibis_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 @@ -47,7 +49,7 @@ 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_start.sh.j2 b/templates/nerve/nerve_start.sh.j2 index 06c4b83..74026ec 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_omnibis_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_start.sh.j2 b/templates/synapse/synapse_start.sh.j2 index 4a3f0b1..17609a0 100644 --- a/templates/synapse/synapse_start.sh.j2 +++ b/templates/synapse/synapse_start.sh.j2 @@ -1,4 +1,8 @@ #!/bin/bash +{% if smartstack_omnibis_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/test1.yml b/tests/test1.yml index 027a4f7..e1a4149 100644 --- a/tests/test1.yml +++ b/tests/test1.yml @@ -1,14 +1,11 @@ --- -# -# 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: diff --git a/tests/test2.yml b/tests/test2.yml index 8eccc5f..7949cd6 100644 --- a/tests/test2.yml +++ b/tests/test2.yml @@ -8,9 +8,9 @@ sudo: True vars_files: - "test2_var.yml" - + pre_tasks: - + - name: superservice template: src="./superservice.j2" diff --git a/tests/test3.yml b/tests/test3.yml new file mode 100644 index 0000000..6d11500 --- /dev/null +++ b/tests/test3.yml @@ -0,0 +1,26 @@ +--- + +- name: Provision my keys + hosts: all + sudo: True + vars_files: + - "test3_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 + + 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..d08c923 --- /dev/null +++ b/tests/test3_var.yml @@ -0,0 +1,110 @@ +--- +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" +smartstack_omnibis_install : True +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 From 33216dbf5de6e423e36a680ea3c5b32186fdc19c Mon Sep 17 00:00:00 2001 From: Adham Helal Date: Tue, 16 Jun 2015 15:41:23 +0200 Subject: [PATCH 2/9] Typo fix --- defaults/main.yml | 8 ++++---- tasks/main.yml | 2 +- tasks/omnibus.yml | 10 +++++----- tasks/synapse.yml | 4 ++-- templates/nerve/nerve_start.sh.j2 | 2 +- templates/synapse/synapse_start.sh.j2 | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 2322170..f95ebd3 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -9,10 +9,10 @@ smartstack_env_variable : smartstack_base_log_dir : "/var/log/smartstack" # Omnibus Options -smartstack_omnibis_install : False -smartstack_omnibis_url : "https://github.com/yetu/omnibus-smartstack/releases/download/0.0.1/smartstack_0.0.1-1_amd64.deb" -smartstack_omnibis_sha256 : "548fbc3a92ec951bc8b1c3b086f1a1731cd859b727fd5897b6d92013255721ea" -smartstack_omnibis_src : "/opt/smartstack/src" +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 diff --git a/tasks/main.yml b/tasks/main.yml index 0786dfd..1927e36 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -15,7 +15,7 @@ tags: [ nerve, synapse, serf ] - include : omnibus.yml - when: smartstack_omnibis_install + when: smartstack_omnibus_install tags: [ nerve, synapse ] - include : nerve.yml diff --git a/tasks/omnibus.yml b/tasks/omnibus.yml index 75e26db..df24f94 100644 --- a/tasks/omnibus.yml +++ b/tasks/omnibus.yml @@ -2,7 +2,7 @@ - name: omnibus | Create base source directory file: - path="{{ smartstack_omnibis_src }}" + path="{{ smartstack_omnibus_src }}" owner="{{ smartstack_user }}" group="{{ smartstack_user }}" mode=0755 @@ -10,9 +10,9 @@ - name: omnibus | Get binary get_url: - url="{{ smartstack_omnibis_url }}" - dest="{{ smartstack_omnibis_src }}" - sha256sum="{{ smartstack_omnibis_sha256 | default(omit) }}" + 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 @@ -24,5 +24,5 @@ - name: omnibus | Install omnibus deb apt: - deb="{{ smartstack_omnibis_src }}/{{ omnibus_packagename |default(smartstack_omnibis_url | basename) }}" + 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/synapse.yml b/tasks/synapse.yml index 4d6b453..c102c2f 100644 --- a/tasks/synapse.yml +++ b/tasks/synapse.yml @@ -26,7 +26,7 @@ force="no" version="{{synapse_reference}}" accept_hostkey=true - when: not smartstack_omnibis_install + when: not smartstack_omnibus_install sudo_user: "{{smartstack_user}}" - name: synapse | Install synapse @@ -36,7 +36,7 @@ environment: smartstack_env_variable register: synapse_bundle_install changed_when: synapse_bundle_install.stdout.find('Installing') != -1 - when: not smartstack_omnibis_install + when: not smartstack_omnibus_install sudo_user: "{{smartstack_user}}" #Maybe include in common only rather in synapse and nerve diff --git a/templates/nerve/nerve_start.sh.j2 b/templates/nerve/nerve_start.sh.j2 index 74026ec..ff81fa2 100644 --- a/templates/nerve/nerve_start.sh.j2 +++ b/templates/nerve/nerve_start.sh.j2 @@ -1,5 +1,5 @@ #!/bin/bash -{% if smartstack_omnibis_install %} +{% if smartstack_omnibus_install %} /opt/smartstack/bin/nerve --config {{nerve_home}}/config.json >> {{nerve_log_file}} 2>&1 {% else %} cd {{ nerve_install_dir }} diff --git a/templates/synapse/synapse_start.sh.j2 b/templates/synapse/synapse_start.sh.j2 index 17609a0..b5c024a 100644 --- a/templates/synapse/synapse_start.sh.j2 +++ b/templates/synapse/synapse_start.sh.j2 @@ -1,5 +1,5 @@ #!/bin/bash -{% if smartstack_omnibis_install %} +{% if smartstack_omnibus_install %} /opt/smartstack/bin/synapse --config {{ synapse_home}}/config.json >> {{synapse_log_file}} 2>&1 {% else %} cd {{synapse_install_dir}} From a958c821604338f62dd528265dd5f20751e7b4dd Mon Sep 17 00:00:00 2001 From: Adham Helal Date: Tue, 16 Jun 2015 15:41:48 +0200 Subject: [PATCH 3/9] Fix directory issues with omnibus + typo fix --- tasks/nerve.yml | 14 +++++++++++--- templates/nerve/nerve_init.sh.j2 | 4 ++-- templates/synapse/synapse_init.sh.j2 | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tasks/nerve.yml b/tasks/nerve.yml index 49599be..9c56910 100644 --- a/tasks/nerve.yml +++ b/tasks/nerve.yml @@ -1,14 +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_omnibis_install + when: not smartstack_omnibus_install sudo_user: "{{smartstack_user}}" - name: nerve | Install nerve @@ -18,7 +26,7 @@ environment: smartstack_env_variable register: nerve_bundle_install changed_when: nerve_bundle_install.stdout.find('Installing') != -1 - when: not smartstack_omnibis_install + when: not smartstack_omnibus_install sudo_user: "{{smartstack_user}}" #Maybe include in common only rather in synapse and nerve 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/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" From dc8c84cc31f8abd66830c033c8e3b13e3ee74966 Mon Sep 17 00:00:00 2001 From: Adham Helal Date: Tue, 16 Jun 2015 15:42:36 +0200 Subject: [PATCH 4/9] ruby install for omnibus test not needed & typo fix --- tests/test3_var.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test3_var.yml b/tests/test3_var.yml index d08c923..69e3946 100644 --- a/tests/test3_var.yml +++ b/tests/test3_var.yml @@ -5,7 +5,8 @@ synapse_install : True synapse_selected_services : [ "postgresql" ] serf_masters : [ "127.0.0.1" ] serf_bind : "0.0.0.0" -smartstack_omnibis_install : True +smartstack_omnibus_install : True +ruby_install : False ip_match_enabled : True ip_fallback : True ip_match_rules : From f32774215a79caee17e94684ad3e8410d2c6bdcc Mon Sep 17 00:00:00 2001 From: Adham Helal Date: Tue, 16 Jun 2015 16:00:57 +0200 Subject: [PATCH 5/9] Make installing git optional --- defaults/main.yml | 3 ++- tasks/common.yml | 6 +++--- tasks/synapse.yml | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index f95ebd3..97a2d61 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -144,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/tasks/common.yml b/tasks/common.yml index 46fcc9d..4a8bdb8 100644 --- a/tasks/common.yml +++ b/tasks/common.yml @@ -6,11 +6,11 @@ home="{{smartstack_home}}" 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/synapse.yml b/tasks/synapse.yml index c102c2f..6e70aa7 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 From dd94b14b589bf4b245bf3399e702e6336adc0f3d Mon Sep 17 00:00:00 2001 From: Adham Helal Date: Tue, 16 Jun 2015 16:55:59 +0200 Subject: [PATCH 6/9] Reorder tests to run omnibus first --- tests/test1.yml | 6 --- tests/test1_var.yml | 102 ++++++++++++++++++++++++++++++++++++++++++-- tests/test2.yml | 18 ++++++-- tests/test2_var.yml | 100 ++----------------------------------------- tests/test3.yml | 12 +++++- tests/test3_var.yml | 2 - 6 files changed, 126 insertions(+), 114 deletions(-) diff --git a/tests/test1.yml b/tests/test1.yml index e1a4149..ade91cc 100644 --- a/tests/test1.yml +++ b/tests/test1.yml @@ -6,11 +6,5 @@ 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 7949cd6..e81b788 100644 --- a/tests/test2.yml +++ b/tests/test2.yml @@ -1,7 +1,4 @@ --- -# -# This playbook deploys your keys to the vagrant -# - name: Provision my keys hosts: all @@ -11,11 +8,24 @@ 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 index 6d11500..9786002 100644 --- a/tests/test3.yml +++ b/tests/test3.yml @@ -1,13 +1,15 @@ --- +# +# This playbook deploys your keys to the vagrant +# - name: Provision my keys hosts: all sudo: True vars_files: - - "test3_var.yml" + - "test2_var.yml" pre_tasks: - - name: Check if omibus was installed before stat: path=/opt/smartstack/bin/ @@ -22,5 +24,11 @@ - "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 index 69e3946..f3277e4 100644 --- a/tests/test3_var.yml +++ b/tests/test3_var.yml @@ -5,8 +5,6 @@ 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 : From a4095b654111268c57084cee2c2c472bf438c5ab Mon Sep 17 00:00:00 2001 From: Adham Helal Date: Thu, 26 Nov 2015 10:33:15 +0100 Subject: [PATCH 7/9] Super app support --- demo/demo1-var.yml | 4 ++ demo/demo2-var.yml | 10 +++- demo/index.html.j2 | 11 ++++ demo/service.j2 | 1 + demo/superapp.sh.j2 | 110 +++++++++++++++++++++++++++++++++++ demo/vagrant-provision.yml | 33 +++++++++-- tests/run_vagrant_kitchen.sh | 0 7 files changed, 162 insertions(+), 7 deletions(-) create mode 100644 demo/index.html.j2 create mode 100644 demo/service.j2 create mode 100644 demo/superapp.sh.j2 mode change 100755 => 100644 tests/run_vagrant_kitchen.sh diff --git a/demo/demo1-var.yml b/demo/demo1-var.yml index f651037..15c023b 100644 --- a/demo/demo1-var.yml +++ b/demo/demo1-var.yml @@ -2,6 +2,7 @@ nerve_install : True 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 @@ -16,3 +17,6 @@ packages_to_install : - "postgresql" ### ruby_install : True + +## App config +color : "#D80000" \ No newline at end of file diff --git a/demo/demo2-var.yml b/demo/demo2-var.yml index 12a4ffd..d9cf7f3 100644 --- a/demo/demo2-var.yml +++ b/demo/demo2-var.yml @@ -2,8 +2,9 @@ nerve_install : False synapse_install : True synapse_selected_services : [ "postgresql" ] -serf_bind : "{{service_ip}}" + 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.*" @@ -13,6 +14,9 @@ smartstack_services_files : "services.yml" ##### #Since this is a demo we will make a list of packages to install packages_to_install : - - "postgresql-client" + - "postgresql-client" ### -ruby_install : True \ No newline at end of file +ruby_install : True + +## +color : "#3300CC" diff --git a/demo/index.html.j2 b/demo/index.html.j2 new file mode 100644 index 0000000..c5d1bc7 --- /dev/null +++ b/demo/index.html.j2 @@ -0,0 +1,11 @@ + + + + + A Small Hello + + + +

Hi I am {{ inventory_hostname }}

+ + \ No newline at end of file diff --git a/demo/service.j2 b/demo/service.j2 new file mode 100644 index 0000000..7e5cfb4 --- /dev/null +++ b/demo/service.j2 @@ -0,0 +1 @@ +python -m SimpleHTTPServer \ 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..ccea214 100644 --- a/demo/vagrant-provision.yml +++ b/demo/vagrant-provision.yml @@ -11,13 +11,22 @@ ## 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 : "-m SimpleHTTPServer" + 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" @@ -34,16 +43,32 @@ apt: update_cache=yes + - name: Install superapp + template: + src="index.html.j2" + dest="{{superapp_pwd}}/index.html" + + - name: Install superapp service + template: + src="superapp.sh.j2" + dest="/etc/init.d/superapp" + mode=0755 + + - name: Enable superapp service + service: + name=superapp + state=restarted + - name: Install demo packages apt: - name="{{item}}" + name="{{item}}" with_items: packages_to_install when : packages_to_install is defined - name : 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" diff --git a/tests/run_vagrant_kitchen.sh b/tests/run_vagrant_kitchen.sh old mode 100755 new mode 100644 From ddf9d4b34ca30d5667f44ba775d4174d7b1888c9 Mon Sep 17 00:00:00 2001 From: Adham Helal Date: Fri, 11 Dec 2015 11:16:08 +0100 Subject: [PATCH 8/9] Demo update to user supper app and add another box --- demo/Vagrantfile | 7 +++-- demo/defaults-var.yml | 56 +++++++++++++++++++++++++++++++++++++- demo/demo1-var.yml | 8 ++++-- demo/demo2-var.yml | 12 +++++--- demo/demo3-var.yml | 22 +++++++++++++++ demo/index.html.j2 | 11 -------- demo/nginx_default.conf | 9 ++++++ demo/service.j2 | 1 - demo/superapp.py.j2 | 47 ++++++++++++++++++++++++++++++++ demo/vagrant-provision.yml | 47 ++++++++++++++++++++++++++++---- 10 files changed, 193 insertions(+), 27 deletions(-) create mode 100644 demo/demo3-var.yml delete mode 100644 demo/index.html.j2 create mode 100644 demo/nginx_default.conf delete mode 100644 demo/service.j2 create mode 100644 demo/superapp.py.j2 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 15c023b..2300e4d 100644 --- a/demo/demo1-var.yml +++ b/demo/demo1-var.yml @@ -1,7 +1,7 @@ --- 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}}" @@ -10,13 +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" \ No newline at end of file +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 d9cf7f3..de41098 100644 --- a/demo/demo2-var.yml +++ b/demo/demo2-var.yml @@ -1,7 +1,9 @@ --- -nerve_install : False +nerve_install : True +nerve_selected_services : [ "superapp" ] + synapse_install : True -synapse_selected_services : [ "postgresql" ] +synapse_selected_services : [ "postgresql"] serf_masters : [ "192.168.56.150", "192.168.56.151"] serf_bind : "{{service_ip}}" @@ -10,13 +12,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-client" + - "python-psycopg2" + ### 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/index.html.j2 b/demo/index.html.j2 deleted file mode 100644 index c5d1bc7..0000000 --- a/demo/index.html.j2 +++ /dev/null @@ -1,11 +0,0 @@ - - - - - A Small Hello - - - -

Hi I am {{ inventory_hostname }}

- - \ 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/service.j2 b/demo/service.j2 deleted file mode 100644 index 7e5cfb4..0000000 --- a/demo/service.j2 +++ /dev/null @@ -1 +0,0 @@ -python -m SimpleHTTPServer \ 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/vagrant-provision.yml b/demo/vagrant-provision.yml index ccea214..9c44153 100644 --- a/demo/vagrant-provision.yml +++ b/demo/vagrant-provision.yml @@ -8,13 +8,14 @@ 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: superapp_user : "{{ lookup('ENV','USER') }}" superapp_pwd : "/home/{{superapp_user}}" superapp_bin : "/usr/bin/python" - superapp_opts : "-m SimpleHTTPServer" + superapp_opts : "superapp.py" localuser : "{{ lookup('ENV','USER') }}" pre_tasks: @@ -39,25 +40,40 @@ 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="index.html.j2" - dest="{{superapp_pwd}}/index.html" + 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: @@ -65,7 +81,7 @@ 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' @@ -73,12 +89,33 @@ 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 From 8c2f8f5ea634dc9e768170dbbfb8bd84faae98ef Mon Sep 17 00:00:00 2001 From: Adham Helal Date: Fri, 11 Dec 2015 11:16:42 +0100 Subject: [PATCH 9/9] Extra assurance for include_vars for services files --- tasks/nerve.yml | 2 +- tasks/synapse.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/nerve.yml b/tasks/nerve.yml index 9c56910..ff54414 100644 --- a/tasks/nerve.yml +++ b/tasks/nerve.yml @@ -32,7 +32,7 @@ #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: diff --git a/tasks/synapse.yml b/tasks/synapse.yml index 6e70aa7..06dd1b3 100644 --- a/tasks/synapse.yml +++ b/tasks/synapse.yml @@ -42,7 +42,7 @@ #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: