diff --git a/playbooks/edx-east/xsy.yml b/playbooks/edx-east/xsy.yml new file mode 100644 index 0000000..c78c279 --- /dev/null +++ b/playbooks/edx-east/xsy.yml @@ -0,0 +1,7 @@ +# Configure an admin instance with jenkins and asgard. +- name: Configure instance(s) + hosts: all + sudo: True + gather_facts: True + roles: + - xsy diff --git a/playbooks/roles/xsy/defaults/main.yml b/playbooks/roles/xsy/defaults/main.yml new file mode 100644 index 0000000..5e514c1 --- /dev/null +++ b/playbooks/roles/xsy/defaults/main.yml @@ -0,0 +1,65 @@ +--- +# +# edX Configuration +# +# github: https://github.com/edx/configuration +# wiki: https://github.com/edx/configuration/wiki +# code style: https://github.com/edx/configuration/wiki/Ansible-Coding-Conventions +# license: https://github.com/edx/configuration/blob/master/LICENSE.TXT +# +## +# Defaults for role xsy +# + +# +# vars are namespace with the module name. +# + + +XSY_USERNAME: '1234_1234@chat.hipchat.com' +XSY_PASSWORD: 'password' +XSY_V1_TOKEN: 'HIPCHAT_V1_TOKEN' +XSY_V2_TOKEN: 'HIPCHAT_V2_TOKEN' +XSY_ROOMS: 'Hammer' +XSY_NAME: 'xsy' +XSY_HANDLE: 'xsy' +XSY_REDIS_URL: 'redis://fakeuser:redispassword@localhost:6379' +XSY_HTTPSERVER_PORT: '8081' +XSY_WORLD_WEATHER_KEY: !!null + + +xsy_service_name: xsy + +xsy_user: xsy +xsy_app_dir: "{{ COMMON_APP_DIR }}/xsy" +xsy_code_dir: "{{ xsy_app_dir }}/xsy" +xsy_venvs_dir: "{{ xsy_app_dir }}/venvs" +xsy_venv_dir: "{{ xsy_venvs_dir }}/xsy" +xsy_venv_bin: "{{ xsy_venv_dir }}/bin" + +xsy_source_repo: "https://github.com/edx/xsy.git" +xsy_version: "HEAD" +xsy_requirements_file: "{{ xsy_code_dir }}/requirements.txt" + +xsy_supervisor_wrapper: "{{ xsy_app_dir }}/xsy-supervisor.sh" + +xsy_environment: + WILL_USERNAME: "{{ XSY_USERNAME }}" + WILL_PASSWORD: "{{ XSY_PASSWORD }}" + WILL_V1_TOKEN: "{{ XSY_V1_TOKEN }}" + WILL_V2_TOKEN: "{{ XSY_V2_TOKEN }}" + WILL_NAME: "{{ XSY_NAME }}" + WILL_HANDLE: "{{ XSY_HANDLE }}" + WILL_REDIS_URL: "{{ XSY_REDIS_URL }}" + WILL_HTTPSERVER_PORT: "{{ XSY_HTTPSERVER_PORT }}" + WILL_WORLD_WEATHER_ONLINE_KEY: "{{ XSY_WORLD_WEATHER_KEY }}" + + +# +# OS packages +# + +xsy_debian_pkgs: [] + +xsy_redhat_pkgs: [] + diff --git a/playbooks/roles/xsy/handlers/main.yml b/playbooks/roles/xsy/handlers/main.yml new file mode 100644 index 0000000..a3f0884 --- /dev/null +++ b/playbooks/roles/xsy/handlers/main.yml @@ -0,0 +1,23 @@ +--- +# +# edX Configuration +# +# github: https://github.com/edx/configuration +# wiki: https://github.com/edx/configuration/wiki +# code style: https://github.com/edx/configuration/wiki/Ansible-Coding-Conventions +# license: https://github.com/edx/configuration/blob/master/LICENSE.TXT +# +# +# +# Handlers for role xsy +# +# Overview: +# +# +- name: restart xsy + supervisorctl: > + name=xsy + supervisorctl_path={{ supervisor_ctl }} + config={{ supervisor_cfg }} + state=restarted + when: not disable_edx_services diff --git a/playbooks/roles/xsy/meta/main.yml b/playbooks/roles/xsy/meta/main.yml new file mode 100644 index 0000000..9d925be --- /dev/null +++ b/playbooks/roles/xsy/meta/main.yml @@ -0,0 +1,24 @@ +--- +# +# edX Configuration +# +# github: https://github.com/edx/configuration +# wiki: https://github.com/edx/configuration/wiki +# code style: https://github.com/edx/configuration/wiki/Ansible-Coding-Conventions +# license: https://github.com/edx/configuration/blob/master/LICENSE.TXT +# +## +# Role includes for role xsy +# +# Example: +# +# dependencies: +# - { +# role: my_role +# my_role_var0: "foo" +# my_role_var1: "bar" +# } + +dependencies: + - supervisor + - redis diff --git a/playbooks/roles/xsy/tasks/main.yml b/playbooks/roles/xsy/tasks/main.yml new file mode 100644 index 0000000..5b69cd2 --- /dev/null +++ b/playbooks/roles/xsy/tasks/main.yml @@ -0,0 +1,103 @@ +--- +# +# edX Configuration +# +# github: https://github.com/edx/configuration +# wiki: https://github.com/edx/configuration/wiki +# code style: https://github.com/edx/configuration/wiki/Ansible-Coding-Conventions +# license: https://github.com/edx/configuration/blob/master/LICENSE.TXT +# +# +# +# Tasks for role xsy +# +# Overview: +# +# +# Dependencies: +# +# +# Example play: +# +# + +- name: create application user + user: > + name="{{ xsy_user }}" home="{{ xsy_app_dir }}" + createhome=no shell=/bin/false + +- name: create xsy user dirs + file: > + path="{{ item }}" state=directory + owner="{{ xsy_user }}" group="{{ common_web_group }}" + with_items: + - "{{ xsy_app_dir }}" + - "{{ xsy_venvs_dir }}" + +- name: setup the xsy env + template: > + src="xsy_env.j2" dest="{{ xsy_app_dir }}/xsy_env" + owner="{{ xsy_user }}" group="{{ common_web_user }}" + mode=0644 + notify: restart xsy + +- name: checkout the code + git: > + dest="{{ xsy_code_dir }}" repo="{{ xsy_source_repo }}" + version="{{ xsy_version }}" accept_hostkey=yes + sudo_user: "{{ xsy_user }}" + register: xsy_checkout + notify: restart xsy + +- name: install the requirements + pip: > + requirements="{{ xsy_requirements_file }}" + virtualenv="{{ xsy_venv_dir }}" + state=present + extra_args="-i {{ COMMON_PYPI_MIRROR_URL }}" + sudo_user: "{{ xsy_user }}" + notify: restart xsy + +- name: create the supervisor wrapper + template: > + src="{{ xsy_supervisor_wrapper|basename }}.j2" + dest="{{ xsy_supervisor_wrapper }}" + mode=0755 + sudo_user: "{{ xsy_user }}" + notify: restart xsy + +- name: create a supervisor config + template: > + src=xsy.conf.j2 dest="{{ supervisor_available_dir }}/xsy.conf" + owner="{{ supervisor_user }}" + group="{{ supervisor_user }}" + sudo_user: "{{ supervisor_user }}" + notify: restart xsy + +- name: enable the supervisor config + file: > + src="{{ supervisor_available_dir }}/xsy.conf" + dest="{{ supervisor_cfg_dir }}/xsy.conf" + state=link + force=yes + mode=0644 + sudo_user: "{{ supervisor_user }}" + when: not disable_edx_services + notify: restart xsy + +- name: update supervisor configuration + shell: "{{ supervisor_ctl }} -c {{ supervisor_cfg }} update" + register: supervisor_update + changed_when: supervisor_update.stdout is defined and supervisor_update.stdout != "" + when: not disable_edx_services + +- name: ensure xsy is started + supervisorctl: > + name=xsy + supervisorctl_path={{ supervisor_ctl }} + config={{ supervisor_cfg }} + state=started + when: not disable_edx_services + +- include: tag_ec2.yml tags=deploy + when: COMMON_TAG_EC2_INSTANCE diff --git a/playbooks/roles/xsy/tasks/tag_ec2.yml b/playbooks/roles/xsy/tasks/tag_ec2.yml new file mode 100644 index 0000000..ab38bbb --- /dev/null +++ b/playbooks/roles/xsy/tasks/tag_ec2.yml @@ -0,0 +1,15 @@ +--- + +- name: get instance information + action: ec2_facts + tags: + - deploy + +- name: tag instance + ec2_tag: resource={{ ansible_ec2_instance_id }} region={{ ansible_ec2_placement_region }} + args: + tags: + "version:xsy" : "{{ xsy_source_repo }} {{ xsy_checkout.after |truncate(7,True,'')}}" + when: xsy_checkout.after is defined + tags: + - deploy diff --git a/playbooks/roles/xsy/templates/xsy-supervisor.sh.j2 b/playbooks/roles/xsy/templates/xsy-supervisor.sh.j2 new file mode 100644 index 0000000..c42496f --- /dev/null +++ b/playbooks/roles/xsy/templates/xsy-supervisor.sh.j2 @@ -0,0 +1,6 @@ +#!/bin/bash + +source {{ xsy_app_dir }}/xsy_env +cd {{ xsy_code_dir }} + +{{ xsy_venv_bin }}/python run_will.py diff --git a/playbooks/roles/xsy/templates/xsy.conf.j2 b/playbooks/roles/xsy/templates/xsy.conf.j2 new file mode 100644 index 0000000..597e3aa --- /dev/null +++ b/playbooks/roles/xsy/templates/xsy.conf.j2 @@ -0,0 +1,10 @@ +[program:xsy] + +command={{ xsy_supervisor_wrapper }} +priority=999 +user={{ common_web_user }} +stdout_logfile={{ supervisor_log_dir }}/%(program_name)s-stdout.log +stderr_logfile={{ supervisor_log_dir }}/%(program_name)s-stderr.log +killasgroup=true +stopasgroup=true +stopsignal=QUIT diff --git a/playbooks/roles/xsy/templates/xsy_env.j2 b/playbooks/roles/xsy/templates/xsy_env.j2 new file mode 100644 index 0000000..98e54d1 --- /dev/null +++ b/playbooks/roles/xsy/templates/xsy_env.j2 @@ -0,0 +1,8 @@ +# {{ ansible_managed }} + +{% for name,value in xsy_environment.items() -%} +{%- if value -%} +export {{ name }}='{{ value }}' +{% endif %} +{%- endfor %} +