subspace 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +5 -0
  7. data/CODE_OF_CONDUCT.md +49 -0
  8. data/Gemfile +4 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +54 -0
  11. data/Rakefile +6 -0
  12. data/ansible/roles/apache/defaults/main.yml +7 -0
  13. data/ansible/roles/apache/handlers/main.yml +4 -0
  14. data/ansible/roles/apache/tasks/main.yml +30 -0
  15. data/ansible/roles/apache/templates/project.conf +25 -0
  16. data/ansible/roles/aws/tasks/main.yml +46 -0
  17. data/ansible/roles/common/defaults/main.yml +3 -0
  18. data/ansible/roles/common/handlers/main.yml +3 -0
  19. data/ansible/roles/common/tasks/main.yml +58 -0
  20. data/ansible/roles/common/tasks/swap.yml +41 -0
  21. data/ansible/roles/delayed_job/README.md +9 -0
  22. data/ansible/roles/delayed_job/defaults/main.yml +4 -0
  23. data/ansible/roles/delayed_job/files/deploy-service +2 -0
  24. data/ansible/roles/delayed_job/files/monit-http.conf +3 -0
  25. data/ansible/roles/delayed_job/handlers/main.yml +4 -0
  26. data/ansible/roles/delayed_job/tasks/main.yml +34 -0
  27. data/ansible/roles/delayed_job/templates/delayed-job-monit-rc +16 -0
  28. data/ansible/roles/letsencrypt/defaults/main.yml +2 -0
  29. data/ansible/roles/letsencrypt/tasks/main.yml +93 -0
  30. data/ansible/roles/letsencrypt/templates/project-le-ssl.conf +31 -0
  31. data/ansible/roles/memcache/tasks/main.yml +6 -0
  32. data/ansible/roles/mysql/meta/main.yml +6 -0
  33. data/ansible/roles/mysql/tasks/main.yml +12 -0
  34. data/ansible/roles/mysql/templates/mysql_database.yml +7 -0
  35. data/ansible/roles/mysql2_gem/meta/main.yml +8 -0
  36. data/ansible/roles/mysql2_gem/tasks/main.yml +5 -0
  37. data/ansible/roles/newrelic/handlers/main.yml +5 -0
  38. data/ansible/roles/newrelic/tasks/main.yml +20 -0
  39. data/ansible/roles/nginx/tasks/main.yml +20 -0
  40. data/ansible/roles/nginx/templates/nginx-project +27 -0
  41. data/ansible/roles/papertrail/tasks/main.yml +12 -0
  42. data/ansible/roles/papertrail/templates/log_files.yml +7 -0
  43. data/ansible/roles/postgresql/defaults/main.yml +2 -0
  44. data/ansible/roles/postgresql/handlers/main.yml +4 -0
  45. data/ansible/roles/postgresql/meta/main.yml +7 -0
  46. data/ansible/roles/postgresql/tasks/backups.yml +33 -0
  47. data/ansible/roles/postgresql/tasks/main.yml +37 -0
  48. data/ansible/roles/postgresql/templates/backup.sh +50 -0
  49. data/ansible/roles/puma/tasks/main.yml +29 -0
  50. data/ansible/roles/puma/templates/etc-init-puma-manager.conf +31 -0
  51. data/ansible/roles/puma/templates/etc-init-puma.conf +69 -0
  52. data/ansible/roles/puma/templates/etc-puma.conf +1 -0
  53. data/ansible/roles/puma/templates/puma.rb +29 -0
  54. data/ansible/roles/rails/defaults/main.yml +4 -0
  55. data/ansible/roles/rails/tasks/main.yml +36 -0
  56. data/ansible/roles/rails/templates/application.yml +3 -0
  57. data/ansible/roles/rails/templates/database.yml +19 -0
  58. data/ansible/roles/redis/tasks/main.yml +6 -0
  59. data/ansible/roles/ruby-common/README.md +74 -0
  60. data/ansible/roles/ruby-common/defaults/main.yml +6 -0
  61. data/ansible/roles/ruby-common/meta/main.yml +22 -0
  62. data/ansible/roles/ruby-common/tasks/main.yml +69 -0
  63. data/ansible/roles/ruby-common/templates/install-ruby.j2 +8 -0
  64. data/ansible/roles/ruby-common/templates/rake-env.j2 +3 -0
  65. data/ansible/roles/ruby-common/templates/ruby-gc-wrapper.j2 +5 -0
  66. data/ansible/roles/ruby-common/vars/main.yml +26 -0
  67. data/bin/console +14 -0
  68. data/bin/setup +8 -0
  69. data/exe/subspace +85 -0
  70. data/lib/subspace/railtie.rb +9 -0
  71. data/lib/subspace/version.rb +3 -0
  72. data/lib/subspace.rb +5 -0
  73. data/lib/tasks/provision.rake +12 -0
  74. data/subspace.gemspec +33 -0
  75. data/template/provision/.gitignore +1 -0
  76. data/template/provision/ansible.cfg.erb +5 -0
  77. data/template/provision/group_vars/all.erb +12 -0
  78. data/template/provision/group_vars/template.erb +14 -0
  79. data/template/provision/host_vars/template.erb +4 -0
  80. data/template/provision/hosts.erb +11 -0
  81. data/template/provision/playbook.yml.erb +26 -0
  82. data/template/provision/vars/template.erb +4 -0
  83. metadata +169 -0
@@ -0,0 +1,5 @@
1
+ ---
2
+ - name: Install mysql2 gem dependencies
3
+ apt:
4
+ name: libmysqlclient-dev
5
+ sudo: true
@@ -0,0 +1,5 @@
1
+ ---
2
+ - name: start newrelic agent
3
+ service:
4
+ name: newrelic-sysmond
5
+ state: restarted
@@ -0,0 +1,20 @@
1
+ ---
2
+ - name: Add New Relic apt repo
3
+ apt_repository:
4
+ repo: deb http://apt.newrelic.com/debian/ newrelic non-free
5
+ state: present
6
+
7
+ - name: Add New Relic apt key
8
+ apt_key:
9
+ url: https://download.newrelic.com/548C16BF.gpg
10
+ state: present
11
+
12
+ - name: Install New Relic server agent
13
+ apt:
14
+ pkg: newrelic-sysmond
15
+ state: present
16
+ update_cache: true
17
+ cache_valid_time: 86400
18
+
19
+ - shell: "nrsysmond-config --set license_key={{newrelic_licence}}"
20
+ notify: start newrelic agent
@@ -0,0 +1,20 @@
1
+ - name: Install nginx
2
+ apt: pkg=nginx state=latest
3
+
4
+ - name: Remove the default app
5
+ command: rm -rf /etc/nginx/sites-enabled/default
6
+
7
+ - name: Remove the app's config, if exists
8
+ command: rm -rf /etc/nginx/sites-enabled/default
9
+
10
+ - name: Remove the app's symlink, if exists
11
+ command: rm -rf /etc/nginx/sites-enabled/{{project_name}}
12
+
13
+ - name: Configure nginx for the app
14
+ template: src=nginx-project dest=/etc/nginx/sites-available/{{project_name}} group=www-data owner=www-data force=yes
15
+
16
+ - name: Enable the app
17
+ command: ln -s /etc/nginx/sites-available/{{project_name}} /etc/nginx/sites-enabled/{{project_name}}
18
+
19
+ - name: Restart nginx
20
+ action: service name=nginx state=restarted
@@ -0,0 +1,27 @@
1
+ upstream app {
2
+ # Path to Puma SOCK file, as defined previously
3
+ server unix:/u/apps/{{project_name}}/shared/tmp/sockets/puma.sock fail_timeout=0;
4
+ }
5
+
6
+ server {
7
+ listen 80;
8
+ server_name localhost;
9
+
10
+ root /u/apps/{{project_name}}/current/public;
11
+
12
+ try_files $uri/index.html $uri @app;
13
+
14
+ location @app {
15
+ proxy_pass http://app;
16
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
17
+ proxy_set_header Host $http_host;
18
+ # pass the upgrade headers so websockets work
19
+ proxy_set_header Upgrade $http_upgrade;
20
+ proxy_set_header Connection "upgrade";
21
+ proxy_redirect off;
22
+ }
23
+
24
+ error_page 500 502 503 504 /500.html;
25
+ client_max_body_size 4G;
26
+ keepalive_timeout 10;
27
+ }
@@ -0,0 +1,12 @@
1
+ ---
2
+ - name: Install remote_syslog from papertrail
3
+ command: wget -O /tmp/remote_syslog.tar.gz https://github.com/papertrail/remote_syslog2/releases/download/v0.13/remote_syslog_linux_amd64.tar.gz creates=/usr/bin/remote_syslog
4
+ - command: tar xzf /tmp/remote_syslog.tar.gz chdir=/tmp/ creates=/usr/bin/remote_syslog
5
+ - command: mv /tmp/remote_syslog/remote_syslog /usr/bin/remote_syslog creates=/usr/bin/remote_syslog
6
+ - file: path=/usr/bin/remote_syslog owner=root group=root mode=0755
7
+ - command: wget -O /etc/init.d/remote_syslog https://raw.githubusercontent.com/papertrail/remote_syslog2/v0.13/examples/remote_syslog.init.d creates=/etc/init.d/remote_syslog
8
+ - file: path=/etc/init.d/remote_syslog owner=root group=root mode=0755
9
+ - file: path=/tmp/remote_syslog/ state=absent
10
+ - file: path=/tmp/remote_syslog.tar.gz state=absent
11
+ - service: name=remote_syslog state=restarted enabled=yes
12
+ - template: src=log_files.yml dest=/etc/log_files.yml owner=root group=root mode=0644
@@ -0,0 +1,7 @@
1
+ # Variables: papertrail_host, papertrail_port
2
+ files:
3
+ - /var/log/apache2/error.log
4
+ - /u/apps/{{project_name}}/shared/log/{{rails_env}}.log
5
+ destination:
6
+ host: {{papertrail_host}}
7
+ port: {{papertrail_port}}
@@ -0,0 +1,2 @@
1
+ ---
2
+ backups_enabled: true
@@ -0,0 +1,4 @@
1
+ ---
2
+ - name: postgresql restart
3
+ service: name=postgresql state=restarted
4
+ sudo: yes
@@ -0,0 +1,7 @@
1
+ ---
2
+ dependencies:
3
+ - {
4
+ role: zenoamaro.postgresql,
5
+ sudo: true,
6
+ notify: postgresql restart
7
+ }
@@ -0,0 +1,33 @@
1
+ ---
2
+ - name: Create Backups directories
3
+ file:
4
+ owner: "{{deploy_user}}"
5
+ path: "/u/apps/{{project_name}}/shared/db/backups"
6
+ state: directory
7
+
8
+ - file: path=/u/apps/{{project_name}}/shared/db/backups/backup.hourly state=directory mode=0755 owner={{deploy_user}}
9
+ - file: path=/u/apps/{{project_name}}/shared/db/backups/backup.daily state=directory mode=0755 owner={{deploy_user}}
10
+ - file: path=/u/apps/{{project_name}}/shared/db/backups/backup.weekly state=directory mode=0755 owner={{deploy_user}}
11
+ - file: path=/u/apps/{{project_name}}/shared/db/backups/backup.monthly state=directory mode=0755 owner={{deploy_user}}
12
+
13
+
14
+ - name: Copy backup script
15
+ template:
16
+ owner: "{{deploy_user}}"
17
+ src: backup.sh
18
+ dest: "/u/apps/{{project_name}}/shared/db/backup.sh"
19
+ mode: 0755
20
+
21
+ - name: Remove old backup cron job because it had the wrong name
22
+ cron:
23
+ user: "{{deploy_user}}"
24
+ name: "check dirs"
25
+ state: "absent"
26
+
27
+ - name: Install backup cron job
28
+ when: backups_enabled
29
+ cron:
30
+ user: "{{deploy_user}}"
31
+ name: "Hourly backups"
32
+ minute: "0"
33
+ job: "/u/apps/{{project_name}}/shared/db/backup.sh"
@@ -0,0 +1,37 @@
1
+ ---
2
+ - name: Create postgresql user
3
+ postgresql_user:
4
+ name: "{{database_user}}"
5
+ password: "{{database_password}}"
6
+ state: present
7
+ sudo: yes
8
+ sudo_user: postgres
9
+
10
+ - name: Create postgresql database
11
+ postgresql_db:
12
+ name: "{{database_name}}"
13
+ owner: "{{database_user}}"
14
+ template: template1
15
+ state: present
16
+ sudo: yes
17
+ sudo_user: postgres
18
+
19
+ - name: Grant all privileges on database to user
20
+ postgresql_privs:
21
+ database: "{{database_name}}"
22
+ privs: ALL
23
+ roles: "{{database_user}}"
24
+ state: present
25
+ type: database
26
+ sudo: yes
27
+ sudo_user: postgres
28
+
29
+ - name: "Enable postgres hstore"
30
+ sudo: yes
31
+ sudo_user: postgres
32
+ postgresql_ext:
33
+ db: "{{database_name}}"
34
+ name: hstore
35
+ state: present
36
+
37
+ - include: backups.yml
@@ -0,0 +1,50 @@
1
+ #!/bin/bash
2
+ # Julius Zaromskis
3
+ # Modified by Brian Samson to support postgres instead
4
+ # Backup rotation
5
+
6
+ # Storage folder where to move backup files
7
+ # Must contain backup.monthly backup.weekly backup.daily folders
8
+ storage=/u/apps/{{project_name}}/shared/db/backups
9
+
10
+ # Destination file names
11
+ date_hourly=`date +"%Y%m%d%H%M"`
12
+ filename="$date_hourly.dump"
13
+ #date_weekly=`date +"%V sav. %m-%Y"`
14
+ #date_monthly=`date +"%m-%Y"`
15
+
16
+ month_day=`date +"%d"`
17
+ week_day=`date +"%u"`
18
+ hour=`date +"%H"`
19
+
20
+
21
+ if [ "$hour" -eq 0 ] ; then
22
+ # at midnight we do the daily logic
23
+ # On first month day do
24
+ if [ "$month_day" -eq 1 ] ; then
25
+ destination=backup.monthly/$filename
26
+ else
27
+ # On saturdays do
28
+ if [ "$week_day" -eq 6 ] ; then
29
+ destination=backup.weekly/$filename
30
+ else
31
+ destination=backup.daily/$filename
32
+ fi
33
+ fi
34
+ else
35
+ # Every other hour just put it in the hourly
36
+ destination=backup.hourly/$filename
37
+ fi
38
+
39
+ #destination is set so actually do the backup
40
+ $(PGPASSWORD={{database_password}} pg_dump --verbose -Fc --host=localhost --username={{database_user}} --file $storage/$destination {{database_name}})
41
+
42
+ # then clean old ones
43
+ # hourly - for 48 hours
44
+ find $storage/backup.hourly/ -mmin +2880 -exec rm -rv {} \;
45
+ # daily - keep for 14 days
46
+ find $storage/backup.daily/ -mtime +14 -exec rm -rv {} \;
47
+ # weekly - keep for 60 days
48
+ find $storage/backup.weekly/ -mtime +60 -exec rm -rv {} \;
49
+ # monthly - keep for 300 days
50
+ find $storage/backup.monthly/ -mtime +300 -exec rm -rv {} \;
@@ -0,0 +1,29 @@
1
+ - name: Add puma-manager
2
+ template: src=etc-init-puma-manager.conf dest=/etc/init/puma-manager.conf force=yes mode=755
3
+ tags: puma
4
+
5
+ - name: Add puma config
6
+ template: src=etc-puma.conf dest=/etc/puma.conf force=yes mode=755
7
+ tags: puma
8
+
9
+ - name: Add puma init script
10
+ template: src=etc-init-puma.conf dest=/etc/init/puma.conf force=yes mode=755
11
+ tags: puma
12
+
13
+ # - name: Add puma shared/config
14
+ # template: src=puma_production.j2 dest=/u/apps/{{project_name}}/shared/config/puma/production.rb force=yes mode=755
15
+ # tags: puma
16
+
17
+ - name: Make shared/tmp/sockets
18
+ file: path=/u/apps/{{project_name}}/shared/tmp/sockets group=deploy owner=deploy state=directory
19
+ tags: tmp
20
+
21
+ - name: Restart puma-manager
22
+ action: service name=puma-manager state=restarted
23
+
24
+ - name: Add Deploy user to sudoers
25
+ lineinfile:
26
+ dest: /etc/sudoers
27
+ state: present
28
+ regexp: "^{{deploy_user}}"
29
+ line: "{{deploy_user}} ALL=NOPASSWD: /usr/sbin/service puma-manager *"
@@ -0,0 +1,31 @@
1
+ # /etc/init/puma-manager.conf - manage a set of Pumas
2
+
3
+ # This example config should work with Ubuntu 12.04+. It
4
+ # allows you to manage multiple Puma instances with
5
+ # Upstart, Ubuntu's native service management tool.
6
+ #
7
+ # See puma.conf for how to manage a single Puma instance.
8
+ #
9
+ # Use "stop puma-manager" to stop all Puma instances.
10
+ # Use "start puma-manager" to start all instances.
11
+ # Use "restart puma-manager" to restart all instances.
12
+ # Crazy, right?
13
+ #
14
+
15
+ description "Manages the set of puma processes"
16
+
17
+ # This starts upon bootup and stops on shutdown
18
+ start on runlevel [2345]
19
+ stop on runlevel [06]
20
+
21
+ # Set this to the number of Puma processes you want
22
+ # to run on this machine
23
+ env PUMA_CONF="/etc/puma.conf"
24
+
25
+ pre-start script
26
+ for i in `cat $PUMA_CONF`; do
27
+ app=`echo $i | cut -d , -f 1`
28
+ logger -t "puma-manager" "Starting $app"
29
+ start puma app=$app
30
+ done
31
+ end script
@@ -0,0 +1,69 @@
1
+ # /etc/init/puma.conf - Puma config
2
+
3
+ # This example config should work with Ubuntu 12.04+. It
4
+ # allows you to manage multiple Puma instances with
5
+ # Upstart, Ubuntu's native service management tool.
6
+ #
7
+ # See workers.conf for how to manage all Puma instances at once.
8
+ #
9
+ # Save this config as /etc/init/puma.conf then manage puma with:
10
+ # sudo start puma app=PATH_TO_APP
11
+ # sudo stop puma app=PATH_TO_APP
12
+ # sudo status puma app=PATH_TO_APP
13
+ #
14
+ # or use the service command:
15
+ # sudo service puma {start,stop,restart,status}
16
+ #
17
+
18
+ description "Puma Background Worker"
19
+
20
+ # no "start on", we don't want to automatically start
21
+ stop on (stopping puma-manager or runlevel [06])
22
+
23
+ # change apps to match your deployment user if you want to use this as a less privileged user (recommended!)
24
+ setuid {{deploy_user}}
25
+ setgid {{deploy_user}}
26
+
27
+ respawn
28
+ respawn limit 3 30
29
+
30
+ instance ${app}
31
+
32
+ script
33
+ # this script runs in /bin/sh by default
34
+ # respawn as bash so we can source in rbenv/rvm
35
+ # quoted heredoc to tell /bin/sh not to interpret
36
+ # variables
37
+
38
+ # source ENV variables manually as Upstart doesn't, eg:
39
+ #. /etc/environment
40
+
41
+ exec /bin/bash <<'EOT'
42
+ # set HOME to the setuid user's home, there doesn't seem to be a better, portable way
43
+ export HOME="$(eval echo ~$(id -un))"
44
+
45
+ if [ -d "/usr/local/rbenv/bin" ]; then
46
+ export PATH="/usr/local/rbenv/bin:/usr/local/rbenv/shims:$PATH"
47
+ elif [ -d "$HOME/.rbenv/bin" ]; then
48
+ export PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH"
49
+ elif [ -f /etc/profile.d/rvm.sh ]; then
50
+ source /etc/profile.d/rvm.sh
51
+ elif [ -f /usr/local/rvm/scripts/rvm ]; then
52
+ source /etc/profile.d/rvm.sh
53
+ elif [ -f "$HOME/.rvm/scripts/rvm" ]; then
54
+ source "$HOME/.rvm/scripts/rvm"
55
+ elif [ -f /usr/local/share/chruby/chruby.sh ]; then
56
+ source /usr/local/share/chruby/chruby.sh
57
+ if [ -f /usr/local/share/chruby/auto.sh ]; then
58
+ source /usr/local/share/chruby/auto.sh
59
+ fi
60
+ # if you aren't using auto, set your version here
61
+ # chruby 2.0.0
62
+ fi
63
+
64
+ cd $app
65
+ logger -t puma "Starting server: $app"
66
+
67
+ exec bundle exec puma -C config/puma.rb
68
+ EOT
69
+ end script
@@ -0,0 +1 @@
1
+ /u/apps/{{project_name}}/current
@@ -0,0 +1,29 @@
1
+ # Change to match your CPU core count
2
+ workers Integer(ENV['WEB_CONCURRENCY'] || 4)
3
+
4
+ threads_count = Integer(ENV['MAX_THREADS'] || 5)
5
+ # Min and Max threads per worker
6
+ threads threads_count, threads_count
7
+
8
+ app_dir = File.expand_path("../..", __FILE__)
9
+
10
+ # Default to production
11
+ rails_env = ENV['RAILS_ENV'] || "production"
12
+ environment rails_env
13
+
14
+ # Set up socket location
15
+ bind "unix://#{app_dir}/tmp/sockets/puma.sock"
16
+
17
+ # Logging
18
+ stdout_redirect "#{app_dir}/log/puma.stdout.log", "#{app_dir}/log/puma.stderr.log", true
19
+
20
+ # Set master PID and state locations
21
+ pidfile "#{app_dir}/tmp/pids/puma.pid"
22
+ state_path "#{app_dir}/tmp/pids/puma.state"
23
+ activate_control_app
24
+
25
+ on_worker_boot do
26
+ require "active_record"
27
+ ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
28
+ ActiveRecord::Base.establish_connection(YAML.load_file("#{app_dir}/config/database.yml")[rails_env])
29
+ end
@@ -0,0 +1,4 @@
1
+ ---
2
+ database_pool: 5
3
+ database_name: "{{project_name}}_{{rails_env}}"
4
+ database_user: "{{project_name}}"
@@ -0,0 +1,36 @@
1
+ ---
2
+ - name: Install rails apt dependencies
3
+ apt:
4
+ name: "{{item}}"
5
+ with_items:
6
+ - git
7
+ - imagemagick
8
+ - libffi-dev
9
+ - libgmp3-dev
10
+ - libmagickwand-dev
11
+ - libpq-dev
12
+ - libxslt-dev
13
+ - nodejs
14
+ - zlib1g-dev
15
+ sudo: true
16
+
17
+ - name: Create /u/apps/{{project_name}}/shared/config
18
+ file:
19
+ path: /u/apps/{{project_name}}/shared/config/
20
+ state: directory
21
+ sudo: true
22
+ sudo_user: "{{deploy_user}}"
23
+
24
+ - name: Create database.yml
25
+ template:
26
+ src: database.yml
27
+ dest: /u/apps/{{project_name}}/shared/config/database.yml
28
+ sudo: true
29
+ sudo_user: "{{deploy_user}}"
30
+
31
+ - name: Create application.yml
32
+ template:
33
+ src: application.yml
34
+ dest: /u/apps/{{project_name}}/shared/config/application.yml
35
+ sudo: true
36
+ sudo_user: "{{deploy_user}}"
@@ -0,0 +1,3 @@
1
+ {% for key, value in appyml.iteritems() %}
2
+ {{key}}: "{{value}}"
3
+ {% endfor %}
@@ -0,0 +1,19 @@
1
+ {{rails_env}}:
2
+ adapter: postgresql
3
+ encoding: unicode
4
+ pool: {{database_pool}}
5
+ database: {{database_name}}
6
+ username: {{database_user}}
7
+ password: {{database_password}}
8
+ host: {{database_host}}
9
+
10
+ {% if databaseyml_addendum is defined %}
11
+ {% for dict in databaseyml_addendum %}
12
+ {% for name, config in dict.iteritems() %}
13
+ {{name}}:
14
+ {% for key, value in config.iteritems() %}
15
+ {{key}}: {{value}}
16
+ {% endfor %}
17
+ {% endfor %}
18
+ {% endfor %}
19
+ {% endif %}
@@ -0,0 +1,6 @@
1
+ ---
2
+ - name: Install Redis
3
+ apt:
4
+ pkg: redis-server
5
+ state: present
6
+ update_cache: true
@@ -0,0 +1,74 @@
1
+ ruby-common
2
+ ========
3
+
4
+ Ansible role that compiles and installs [Ruby](https://www.ruby-lang.org) and [Bundler](http://bundler.io). This role is generic enough to support any version of Ruby, and it is best used in conjunction with another role that supplies the required variables and that depends on this common base.
5
+
6
+ For example, the following roles use ruby-common:
7
+
8
+ * ruby-1.9.3
9
+ * [Galaxy](https://galaxy.ansible.com/list#/roles/144)
10
+ * [GitHub](https://github.com/jlund/ansible-ruby-1.9.3)
11
+ * ruby-2.0.0
12
+ * [Galaxy](https://galaxy.ansible.com/list#/roles/145)
13
+ * [GitHub](https://github.com/jlund/ansible-ruby-2.0.0)
14
+ * ruby-2.1
15
+ * [Galaxy](https://galaxy.ansible.com/list#/roles/146)
16
+ * [GitHub](https://github.com/jlund/ansible-ruby-2.1)
17
+
18
+
19
+ Role Variables
20
+ --------------
21
+
22
+ **Variables that *must* be set by the user (or another role)**
23
+
24
+ > ruby_version: This variable controls the version of Ruby that will be compiled and installed. It should correspond with the tarball filename excluding the ".tar.gz" extension (e.g. "ruby-1.9.3-p484").
25
+
26
+ > ruby_checksum: The SHA256 checksum of the gzipped tarball that will be downloaded and compiled.
27
+
28
+ > ruby_download_location: The URL that the tarball should be retrieved from. Using the ruby_version variable within this variable is a good practice (e.g. "http://cache.ruby-lang.org/pub/ruby/1.9/{{ ruby_version }}.tar.gz").
29
+
30
+ **Variables that *can* be set by the user (or another role)**
31
+
32
+ > rails_env: This role includes a convenient shell script that lets you invoke Rake commands using Bundler with the proper RAILS_ENV environment variable set. This script is placed in /usr/local/bin/rake-env. This can be useful in other tasks (e.g. if you wanted to run a Rake task using the command module). This variable is used to control the Rails environment for this script and is set to "production" by default.
33
+
34
+ > ruby_bundler_flags: This variable controls any extra flags that you would like to be passed to RubyGems when Bundler is first installed. For example, you can set this to "--no-document" to disable documentation generation, or "--version VERSION" to install a particular version of Bundler. The default is blank, and no extra flags are passed.
35
+
36
+ This role also includes a GC wrapper shell script that lets you tune the Ruby garbage collection settings. This script is placed in /usr/local/bin/ruby-gc-wrapper. These three variables are used within the template that generates this script:
37
+
38
+ > ruby_free_min: Sets the RUBY_FREE_MIN environment variable.
39
+
40
+ > ruby_gc_malloc_limit: Sets the RUBY_GC_MALLOC_LIMIT environment variable.
41
+
42
+ > ruby_heap_min_slots: Sets the RUBY_HEAP_MIN_SLOTS environment variable.
43
+
44
+ These variables are blank by default (i.e. they do not change the GC settings at all) and your chosen GC settings will only be used if the `ruby-gc-wrapper` executable is used instead of `ruby`.
45
+
46
+ **Variables that are set by the role itself (and that shouldn't need to be modified)**
47
+
48
+ > ruby_apt_dependencies: Controls the installation of dependencies that are necessary in order to properly compile Ruby on Debian and Ubuntu. Includes libreadline-dev, libssl-dev, libyaml-dev, and zlib1g-dev by default.
49
+
50
+ > ruby_yum_dependencies: Controls the installation of dependencies that are necessary in order to properly compile Ruby on Amazon Linux, CentOS, and Red Hat. Includes readline-devel, openssl-devel, libyaml-devel, and zlib-devel by default.
51
+
52
+ > ruby_symlinks: Controls which binaries will be symlinked into /usr/local/bin. Includes bundle, erb, gem, irb, rake, rdoc, ri, ruby, and testrb by default.
53
+
54
+ > ruby_location: Controls where Ruby will be installed and is set to "/opt/{{ ruby_version }}" by default.
55
+
56
+ > ruby_executable: Provides a convenient pointer to the Ruby binary that lets you run Ruby commands from other roles. It is set to "{{ ruby_location }}/bin/ruby" by default.
57
+
58
+ License
59
+ -------
60
+
61
+ The MIT License (MIT)
62
+
63
+ Copyright (c) 2013-2014 Joshua Lund
64
+
65
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
66
+
67
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
68
+
69
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
70
+
71
+ Author Information
72
+ ------------------
73
+
74
+ You can find me on [Twitter](https://twitter.com/joshualund), and on [GitHub](https://github.com/jlund/). I also occasionally blog at [MissingM](http://missingm.co).
@@ -0,0 +1,6 @@
1
+ ---
2
+ rails_env: "production"
3
+ ruby_bundler_flags: ""
4
+ ruby_free_min: ""
5
+ ruby_gc_malloc_limit: ""
6
+ ruby_heap_min_slots: ""
@@ -0,0 +1,22 @@
1
+ ---
2
+ galaxy_info:
3
+ author: "Joshua Lund"
4
+ description: "Ansible role that compiles and installs Ruby (https://www.ruby-lang.org) and Bundler (http://bundler.io)."
5
+ license: MIT
6
+ min_ansible_version: 1.4
7
+ platforms:
8
+ - name: Amazon
9
+ versions:
10
+ - all
11
+ - name: Debian
12
+ versions:
13
+ - all
14
+ - name: EL
15
+ versions:
16
+ - all
17
+ - name: Ubuntu
18
+ versions:
19
+ - all
20
+ categories:
21
+ - development
22
+ dependencies: []
@@ -0,0 +1,69 @@
1
+ ---
2
+ - name: Update APT cache
3
+ apt: update_cache=yes
4
+ when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
5
+
6
+ - name: Retrieve the number of cores that are available for compilation
7
+ command: nproc
8
+ register: cores
9
+
10
+ - name: Install APT prerequisite packages that are necessary to compile applications and gems with native extensions
11
+ apt: pkg={{ item }}
12
+ with_items:
13
+ - autoconf
14
+ - build-essential
15
+ when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
16
+
17
+ - name: Install yum prerequisite packages that are necessary to compile applications and gems with native extensions
18
+ yum: name="{{ item }}"
19
+ with_items:
20
+ - autoconf
21
+ - "@Developer tools"
22
+ when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux' or ansible_distribution == 'Amazon'
23
+
24
+ - name: Install APT Ruby dependencies
25
+ apt: pkg={{ item }}
26
+ state=present
27
+ with_items: ruby_apt_dependencies
28
+ when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
29
+
30
+ - name: Install yum Ruby dependencies
31
+ yum: name={{ item }}
32
+ with_items: ruby_yum_dependencies
33
+ when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux' or ansible_distribution == 'Amazon'
34
+
35
+ - name: Download the Ruby source code
36
+ get_url: url={{ ruby_download_location }}
37
+ dest=/usr/local/src/
38
+ sha256sum={{ ruby_checksum }}
39
+
40
+ - name: Generate the Ruby installation script
41
+ template: src=install-ruby.j2
42
+ dest=/usr/local/src/install-ruby.sh
43
+ owner=root
44
+ group=root
45
+ mode=700
46
+
47
+ - name: Run the Ruby installation script
48
+ command: /usr/local/src/install-ruby.sh
49
+ creates={{ ruby_location }}/bin/ruby
50
+
51
+ - name: Generate the script that allows you to easily run Rake tasks with the correct RAILS_ENV environment variable, and the wrapper script that contains GC settings
52
+ template: src={{ item }}.j2
53
+ dest=/usr/local/bin/{{ item }}
54
+ owner=root
55
+ group=root
56
+ mode=755
57
+ with_items:
58
+ - rake-env
59
+ - ruby-gc-wrapper
60
+
61
+ - name: Install Bundler
62
+ command: "{{ ruby_location }}/bin/gem install bundler {{ ruby_bundler_flags }}
63
+ creates={{ ruby_location }}/bin/bundle"
64
+
65
+ - name: Make Ruby symlinks
66
+ file: path=/usr/local/bin/{{ item }}
67
+ src={{ ruby_location }}/bin/{{ item }}
68
+ state=link
69
+ with_items: ruby_symlinks