Skip to content

Instantly share code, notes, and snippets.

@mdaniel
Created February 19, 2014 00:01
Show Gist options
  • Save mdaniel/9083300 to your computer and use it in GitHub Desktop.
Save mdaniel/9083300 to your computer and use it in GitHub Desktop.
Ansible script to provision GetSentry on a precise (Ubuntu 12.04) machine (or optionally the Vagrantfile); the script will provision to the point where you can run ``sentry init`` and its friends
---
- hosts: all
sudo: true
tasks:
- name: install pip
apt: update_cache=true install_recommends=true state=present
pkg={{item}}
with_items:
- build-essential
- git
- nginx
- python-pip
- python-dev
## be aware that installing this on Ubuntu *starts* the server
- postgresql
- libpq-dev
- supervisor
- name: get virtualenv
pip: name=virtualenv state=present
- name: create the pip config dir
file: state=directory dest=/home/vagrant/.pip
owner=vagrant mode=0755
- name: turn pip caching on
copy:
dest: /home/vagrant/.pip/pip.conf
owner: vagrant
mode: 0644
content: |
[install]
download-cache=/home/vagrant/.cache/pip
- name: create the pip cache dir
file: state=directory dest=/home/vagrant/.cache/pip
owner=vagrant mode=0755
- name: create sentry virtualenv
command: creates=/home/vagrant/venv_sentry/bin/python
virtualenv /home/vagrant/venv_sentry
- name: pip-get sentry and sentry-postgres
pip: virtualenv=/home/vagrant/venv_sentry
name=sentry state=present
with_items:
- sentry
- "sentry[postgres]"
- name: check for existing postgresql sentry user
shell: |
sudo -u postgres psql -c "\du sentry" | grep sentry >/dev/null
ignore_errors: true
register: has_sentry_role
- name: create sentry postgres user
when: has_sentry_role|failed
shell: |
sudo -u postgres \
createuser --no-createdb --no-createrole --no-superuser \
--encrypted --login "sentry"
sudo -u postgres \
psql -c "ALTER ROLE sentry WITH ENCRYPTED PASSWORD 'getsentry';"
echo "Be aware that the default pg_hba.conf uses peer"
echo "authentication if the --host argument is not specified"
echo "when using psql; you will need to put HOST in your sentry.conf also"
- name: check for existing postgresql sentry database
shell: |
sudo -u postgres psql -c "\l" | grep sentry >/dev/null
ignore_errors: true
register: has_sentry_db
- name: create sentry database
when: has_sentry_db|failed
## if one does not use template0, you will see the following error
## createdb: database creation failed: ERROR:
## new encoding (UTF8) is incompatible with the encoding of the template database
shell: |
sudo -u postgres \
createdb --encoding=utf-8 --owner=sentry sentry
- name: create nginx config
copy:
dest: /etc/nginx/sites-available/default
owner: root
mode: 0644
# that client_max_body_size business is to stop "413 Request Entity Too Large"
contents: |
server {
root /usr/share/nginx/www;
index index.html index.htm;
server_name localhost;
client_max_body_size 10M;
location / {
proxy_pass http://localhost:9000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
- name: create sentry supervisor.d file
copy:
dest: /etc/supervisor/conf.d/sentry-web.conf
owner: root
mode: 0644
content: |
[program:sentry-web]
directory=/home/vagrant
command=/home/vagrant/venv_sentry/bin/sentry start http
user=vagrant
autostart=true
autorestart=true
redirect_stderr=true
# this is to ensure there is a EOL on that file
- name: display finished message
shell: |
echo "Your sentry machine is now ready for sentry configuration"
echo "More Info: http://sentry.readthedocs.org/en/latest/quickstart/index.html"
echo "Good luck."
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = '2'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = 'precise'
config.vm.hostname = 'sentry1'
config.vm.network :private_network, ip: '192.168.56.105'
config.vm.provider :virtualbox do |vb|
# vb.gui = true
vb.customize ['modifyvm', :id, '--memory', '1024']
end
## if you find yourself bringing this Vagrant up and down a lot
## you may want to cache those downloads to save some time during
## re-runs of the ansible script
$script1 = <<SCRIPT1
mkdir /root/.pip
mkdir /home/vagrant/.pip
chown vagrant /home/vagrant/.pip
mkdir /home/vagrant/.cache/pip
chown vagrant /home/vagrant/.cache/pip
cat> /home/vagrant/.pip/pip.conf<<PIP
[global]
download-cache = /home/vagrant/.cache/pip
log-file = /home/vagrant/.pip/pip.log
respect-virtualenv = true
PIP
# ansible runs things as root, so root needs to have a pip.conf too
ln -s /home/vagrant/.pip/pip.conf /root/.pip/pip.conf
if test -f /vagrant/cache_pip.tar; then
tar xf /vagrant/cache_pip.tar -C /home/vagrant
fi
if test -f /vagrant/var_cache_apt.tar; then
tar xf /vagrant/var_cache_apt.tar -C /
fi
SCRIPT1
config.vm.provision 'shell', inline: $script1
config.vm.provision 'ansible' do |a|
a.verbose = 'v'
a.playbook = 'sentry_play.yml'
a.extra_vars = {'hostname' => config.vm.hostname}
end
end
@lenards
Copy link

lenards commented Apr 6, 2016

Thanks.

Re: Line 121 in your play - the docs link is now: https://docs.getsentry.com/on-premise/quickstart/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment