Permalink
Browse files

Introduce ansible deploy script.

  • Loading branch information...
mforsyth committed Nov 12, 2015
1 parent 48a3df8 commit ebb99715bf9ae7bd768f9af02f0143cb3da5f0e3
@@ -80,6 +80,11 @@ We've provided some very, very basic recipes and are interested in adding more,
so please send a pull request if you think anything would serve the larger
community.

## Deploying Satellite

If you're deploying Satellite to a Mesos cluster, you might find that installing and configuring it on all of your hosts involves some repetitive busy work.
To help you automate these tasks, we've provided some [Ansible Roles](ansible/).

## Contributing
We need all contributors to fill out our Contributor License Agreement found in
`/cla` before we can accept any code or pull requests.
@@ -0,0 +1,23 @@
# Ansible deploy script

If you're deploying Satellite to a cluster, you'll find that repeatedly changing its configuration on all of your Mesos hosts can involve some repetitive busy work.
We've provided some [Ansible](http://www.ansible.com/) Roles to help you automate these tasks.

These Roles deploy satellite-master and satellite-slave.
systemd is used to launch and supervise the respective satellite processes.
Execute either Role to deploy Satellite initially, OR to apply your latest configuration to an existing installation of Satellite.


## Instructions

1. Create or adjust the Ansible inventory for your Mesos cluster.
You can just list hosts in a flat file (see inventory.sample), or build your inventory dynamically using the more [sophisticated capabilities of Ansible](http://docs.ansible.com/ansible/intro_dynamic_inventory.html).
Either way, you should arrange your inventory such that it contains distinct groups, e.g. 'satellite\_masters' and 'satellite\_slaves', which contain the list of hosts to which you intend to deploy satellite\_master and satellite\_slave respectively.

2. Edit example_playbook.yml so that the settings are appropriate for your cluster.

3. Edit the Satellite configuration files specified by the variables in example_playbook.yml.

4. cd to the directory containing this file.

5. Run "ansible-playbook -i your_inventory example_playbook.yml" to deploy and start satellite\_master on your Mesos master servers, and to deploy and start satellite\_slave on your Mesos slave servers.
@@ -0,0 +1,35 @@
# Copyright 2015 TWO SIGMA OPEN SOURCE, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

- hosts: satellite_masters
gather_facts: false
vars:
satellite_install_dir: /home/admin
master_source_dir: ../satellite-master
master_jar: "{{ master_source_dir }}/target/satellite-master-0.2.0-SNAPSHOT-standalone.jar"
master_config_template: satellite-master-config.clj.j2
riemann_config_file: "{{ master_source_dir }}/config/riemann-config.clj"
roles:
- satellite_master

- hosts: satellite_slaves
gather_facts: false
vars:
satellite_install_dir: /home/admin
slave_source_dir: ../satellite-slave
slave_jar: "{{ slave_source_dir }}/target/satellite-slave-0.2.0-SNAPSHOT-standalone.jar"
slave_config_template: satellite-slave-config.clj.j2
recipes_script: "{{ slave_source_dir }}/bin/satellite-recipes"
roles:
- satellite_slave
@@ -0,0 +1,23 @@
# Copyright 2015 TWO SIGMA OPEN SOURCE, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

[satellite_masters]
sat_master1 ansible_ssh_host=10.10.10.1 ansible_ssh_user=myuser
sat_master2 ansible_ssh_host=10.10.10.2 ansible_ssh_user=myuser
sat_master3 ansible_ssh_host=10.10.10.3 ansible_ssh_user=myuser

[satellite_slaves]
sat_slave1 ansible_ssh_host=10.10.10.4 ansible_ssh_user=myuser
sat_slave2 ansible_ssh_host=10.10.10.5 ansible_ssh_user=myuser
sat_slave3 ansible_ssh_host=10.10.10.6 ansible_ssh_user=myuser
@@ -0,0 +1,61 @@
# Copyright 2015 TWO SIGMA OPEN SOURCE, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---

- name: ensure satellite master installation directory exists
file: path={{ satellite_install_dir }} state=directory
tags:
- master

- name: create satellite master jar unless it already exists
local_action: command lein release-jar chdir="{{ master_source_dir }}" creates="{{ master_jar }}"
tags:
- master
- compile

- name: copy satellite master jar
copy: src={{ master_jar }} dest={{ satellite_install_dir }}/satellite-master.jar
tags:
- master

- name: place satellite master init script
template: src=satellite-master.j2 dest={{ satellite_install_dir }}/satellite-master mode=0755
tags:
- master

- name: place satellite master config
template: src={{ master_config_template }} dest={{ satellite_install_dir }}/satellite-master-config.clj
tags:
- master

- name: place riemann config for satellite master
copy: src={{ riemann_config_file }} dest={{ satellite_install_dir }}/riemann-config.clj
tags:
- master

- name: place satellite master systemctl unit file
template: src=satellite-master.service.j2 dest=/etc/systemd/system/satellite-master.service mode=0755
become: yes
become_method: sudo
tags:
- master
- systemd

- name: restart satellite master
shell: "systemctl restart satellite-master"
become: yes
become_method: sudo
tags:
- master
- systemd
@@ -0,0 +1,25 @@
;; Copyright 2015 TWO SIGMA OPEN SOURCE, LLC
;;
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;;
;; http://www.apache.org/licenses/LICENSE-2.0
;;
;; Unless required by applicable law or agreed to in writing, software
;; distributed under the License is distributed on an "AS IS" BASIS,
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;; See the License for the specific language governing permissions and
;; limitations under the License.

(ns satellite.core)

(def settings
(merge settings
{:mesos-master-url (url/url "http://{{ ansible_ssh_host }}:5050")
:sleep-time 5000
:zookeeper "{{ ansible_ssh_host }}:2181"
:local-whitelist-path "/etc/mesos/whitelist"
:riemann-config "{{ satellite_install_dir }}/riemann-config.clj"
:riemann-tcp-server-options {:host "0.0.0.0"}
:service-host "0.0.0.0"}))
@@ -0,0 +1,18 @@
#!/bin/bash

# Copyright 2015 TWO SIGMA OPEN SOURCE, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cd "{{ satellite_install_dir }}"
exec java -jar "{{ satellite_install_dir }}/satellite-master.jar" "{{ satellite_install_dir }}/satellite-master-config.clj"
@@ -0,0 +1,10 @@
[Unit]
Description=Satellite, Monitoring and Healing for Mesos
Wants=mesos-master.service

[Service]
ExecStart={{ satellite_install_dir }}/satellite-master
Restart=on-failure

[Install]
WantedBy=multi-user.target
@@ -0,0 +1,61 @@
# Copyright 2015 TWO SIGMA OPEN SOURCE, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---

- name: ensure satellite slave installation directory exists
file: path={{ satellite_install_dir }} state=directory
tags:
- slave

- name: create satellite slave jar unless it already exists
local_action: command lein release-jar chdir="{{ slave_source_dir }}" creates="{{ slave_jar }}"
tags:
- slave
- compile

- name: copy satellite slave jar
copy: src={{ slave_jar }} dest={{ satellite_install_dir }}/satellite-slave.jar
tags:
- slave

- name: place satellite slave init script
template: src=satellite-slave.j2 dest={{ satellite_install_dir }}/satellite-slave mode=0755
tags:
- slave

- name: place satellite slave config
template: src={{ slave_config_template }} dest={{ satellite_install_dir }}/satellite-slave-config.clj
tags:
- slave

- name: place recipes script for satellite slave
copy: src={{ recipes_script }} dest={{ satellite_install_dir }}/satellite-recipes mode=0755
tags:
- slave

- name: place satellite slave systemctl unit file
template: src=satellite-slave.service.j2 dest=/etc/systemd/system/satellite-slave.service mode=0755
become: yes
become_method: sudo
tags:
- slave
- systemd

- name: restart satellite slave
shell: "systemctl restart satellite-slave"
become: yes
become_method: sudo
tags:
- slave
- systemd
@@ -0,0 +1,22 @@
;; Copyright 2015 TWO SIGMA OPEN SOURCE, LLC
;;
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;;
;; http://www.apache.org/licenses/LICENSE-2.0
;;
;; Unless required by applicable law or agreed to in writing, software
;; distributed under the License is distributed on an "AS IS" BASIS,
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;; See the License for the specific language governing permissions and
;; limitations under the License.

(def mesos-work-dir "/tmp/mesos")

(def settings
{:satellites [{% for master in groups['satellite_masters'] %}
{:host "{{ hostvars[master]['ansible_ssh_host']}}"}
{% endfor %}]
:service "mesos/slave/"
:comets [(satellite-slave.recipes/free-memory 50 (-> 60 t/seconds))]})
@@ -0,0 +1,19 @@
#!/bin/bash

# Copyright 2015 TWO SIGMA OPEN SOURCE, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

export PATH="$PATH:{{ satellite_install_dir }}"
cd "{{ satellite_install_dir }}"
exec java -jar "{{ satellite_install_dir }}/satellite-slave.jar" "{{ satellite_install_dir }}/satellite-slave-config.clj"
@@ -0,0 +1,10 @@
[Unit]
Description=Satellite, Monitoring and Healing for Mesos
Wants=mesos-slave.service

[Service]
ExecStart={{ satellite_install_dir }}/satellite-slave
Restart=on-failure

[Install]
WantedBy=multi-user.target

0 comments on commit ebb9971

Please sign in to comment.