DEBOPS.RAILS_DEPLOY(5)

NAME
debops.rails_deploy - Deploy Rails applications using Ansible

DEBOPS.RAILS_DEPLOY DEFAULT VARIABLES

---- System ----

rails_deploy_dependencies

    Should certain services/envs be setup for you automatically? Redis will only be setup if you enable background worker support.

    Keep in mind that if you remove ruby then you will be expected to put ruby on the system and ensure its binaries are on the system path.

    rails_deploy_dependencies: ['database', 'redis', 'nginx', 'ruby', 'monit']

rails_deploy_packages

    Which packages do you want installed? Add as many packages as you want, the database_package will automatically pick libpq-dev or libmysqlclient-dev depending on what database you picked.

    rails_deploy_packages: ['{{ rails_deploy_database_package }}']

rails_deploy_user_groups

    A list of additional groups that this app's user belongs to. If you want to be able to ssh into the server then you must include 'sshusers'.

    rails_deploy_user_groups: []

rails_deploy_user_sshkey

    Where should the public ssh key be read in from? This is only used when you have included 'sshusers' in the user_groups list.

    rails_deploy_user_sshkey: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"

    ---- Hosts ----

rails_deploy_hosts_group

    What inventory group does your app belong to? If you want to have multiple apps then make this group gather up all sub-groups such as debops_rails_deploy_myapp and debops_rails_deploy_anotherapp.

    rails_deploy_hosts_group: 'debops_rails_deploy'

rails_deploy_hosts_master

    Which application server should run database related tasks?

    rails_deploy_hosts_master: '{{ groups[rails_deploy_hosts_group][0] }}'

    ---- Git ----

rails_deploy_git_location

    The location repo which will get cloned during each deploy. You can use a remote or local repo.

    rails_deploy_git_location: ''

rails_deploy_git_version

    Which branch or tag should be used?

    rails_deploy_git_version: 'master'

rails_deploy_git_remote

    Which remote should be used?

    rails_deploy_git_remote: 'origin'

    Supply your git provider's api token to automatically set deploy keys. If False you will have to manually add deploy keys for each app server.

rails_deploy_git_access_token

    Supports github and gitlab for now: Github: https://github.com/settings/applications Under personal access tokens, check off 'write:public_key'. You may want to enable other access limits for repo/public_repo, etc..

    Gitlab: https://yourgitlabhost.com/profile/account Your private token should already be there.

    rails_deploy_git_access_token: False

    ---- Deploy ----

rails_deploy_service

    What should the service be named? The default value plucks out your repo name (without .git) from your location.

    rails_deploy_service: "{{ rails_deploy_git_location | basename | replace('.git', '') }}"

rails_deploy_home

    Where should the user's home directory be?

    rails_deploy_home: '/var/local/{{ rails_deploy_service }}'

rails_deploy_src

    Where should the git repository be cloned to?

    rails_deploy_src: '{{ rails_deploy_home }}/{{ rails_deploy_nginx_domains[0] }}/{{ rails_deploy_service }}/src'

rails_deploy_system_env

    What should the system environment be set to?

    rails_deploy_system_env: 'production'

rails_deploy_bundle_without

    A list of environments to skip, it will remove your system env from the list during the deploy phase automatically.

    rails_deploy_bundle_without: ['development', 'staging', 'production', 'test']

rails_deploy_service_timeout

    Timeout for service and worker startup, in seconds

    rails_deploy_service_timeout: '60'

    ---- Backend ----

rails_deploy_backend

    Which backend type are you using? 'unicorn' and 'puma' are supported so far. You can also disable the backend by setting it to False in case you use passenger.

    rails_deploy_backend: 'unicorn'

rails_deploy_backend_bind

    What do you want to listen on? You can choose a tcp addr:port or unix socket. Do not bother to include the socket/tcp prefix, that will be handled for you.

    rails_deploy_backend_bind: '{{ rails_deploy_service_socket }}'

rails_deploy_backend_state

    What state should the backend be in?

    rails_deploy_backend_state: 'started'

rails_deploy_backend_enabled

    FIXME(yaml4rst): Describe what this variable is doing.

    rails_deploy_backend_enabled: True

rails_deploy_backend_always_restart

    When set to true the backend will always restart instead of reload but it will only restart if the repo changed. This makes for hands free deployment at the cost of a few seconds+ of downtime per deploy.

    You may want to combine this with force migrate in which case all you ever have to do is push your app and you don't have to wonder whether or not the code you're changing requires a full restart or not.

    rails_deploy_backend_always_restart: False

    ---- Database ----

rails_deploy_database_create

    Should the database be created by default?

    rails_deploy_database_create: True

rails_deploy_database_prepare

    Should the database get a db:schema:load and db:seed in an idempotent way?

    rails_deploy_database_prepare: True

rails_deploy_database_migrate

    Should the database get automatically migrated in an idempotent way?

    rails_deploy_database_migrate: True

rails_deploy_database_force_migrate

    Should the database get migrated no matter what? You may want to do this as a 1 off command with --extra-vars in case your schema file's checksum somehow gets out of sync and you need to migrate.

    Another use case would be if you have automatic migrations turned off and you just deployed but now you want to do an isolated migration.

    rails_deploy_database_force_migrate: False

rails_deploy_database_adapter

    It supports 'postgresql' or 'mysql' for now.

    rails_deploy_database_adapter: 'postgresql'

rails_deploy_postgresql_cluster

    Make sure this matches your pg cluster info, ignore it if you use mysql.

    rails_deploy_postgresql_cluster: '9.1/main'

rails_deploy_database_host

    Where is your database hosted?

    rails_deploy_database_host: '{{ ansible_fqdn }}'

rails_deploy_database_port

    FIXME(yaml4rst): Describe what this variable is doing.

    rails_deploy_database_port: '5432'  # 3306 for mysql

rails_deploy_postgresql_super_username

    What are your super user names?

    rails_deploy_postgresql_super_username: 'postgres'

rails_deploy_mysql_super_username

    FIXME(yaml4rst): Describe what this variable is doing.

    rails_deploy_mysql_super_username: 'mysql'

rails_deploy_database_user_role_attrs

    What are the roles that should be applied to the app postgres user? See https://docs.ansible.com/postgresql_user_module.html for available options

    rails_deploy_database_user_role_attrs: ''

rails_deploy_database_pool

    What should some of the configuration options be set to?

    rails_deploy_database_pool: 25

rails_deploy_database_timeout

    FIXME(yaml4rst): Describe what this variable is doing.

    rails_deploy_database_timeout: 5000

    ---- Background Worker ----

rails_deploy_worker_enabled

    Enable background worker support. This will create an init.d service, register it with monit and add it into the deploy life cycle.

    rails_deploy_worker_enabled: False

rails_deploy_worker_state

    FIXME(yaml4rst): Describe what this variable is doing.

    rails_deploy_worker_state: 'started'

rails_deploy_worker

    At the moment it only supports sidekiq but resque could happen in the future.

    rails_deploy_worker: 'sidekiq'

rails_deploy_worker_host

    Where is your worker hosted?

    rails_deploy_worker_host: '{{ ansible_fqdn }}'

rails_deploy_worker_port

    FIXME(yaml4rst): Describe what this variable is doing.

    rails_deploy_worker_port: '6379'

rails_deploy_worker_url

    How should the connection be made to the redis server? If your server has a password you must add it here. Example: redis://:mypassword@{{ rails_deploy_worker_host }}:{{ rails_deploy_worker_port }}/0'

    rails_deploy_worker_url: 'redis://{{ rails_deploy_worker_host }}:{{ rails_deploy_worker_port }}/0'

    ---- Commands ----

    Execute shell commands at various points in the deploy life cycle. They are executed in the context of the root directory of your app and are also only ran when your repo has changed.

rails_deploy_pre_migrate_shell_commands

    Shell commands to run before migration They will still run even if you have migrations turned off.

    rails_deploy_pre_migrate_shell_commands: []

rails_deploy_post_migrate_shell_commands

    Shell commands to run after migration They will still run even if you have migrations turned off.

    rails_deploy_post_migrate_shell_commands:
      - 'bundle exec rake assets:precompile'
      - 'rm -rf tmp/cache'

rails_deploy_post_restart_shell_commands

    Shell commands to run after the backend was started Let's say you wanted to execute whenever after your app reloads/restarts:

•   'bundle exec whenever --clear-crontab {{ rails_deploy_service }}'

    This is the absolute last thing that happens during a deploy. They will still run even if you have no backend.

    rails_deploy_post_restart_shell_commands: []

    ---- Services ----

    Add 1 or more custom services related to the app, they will have their state changed on each deploy. The changed_state is the action to take when the state of the git repo has changed.

rails_deploy_extra_services

    They will get restarted/reloaded at the end of the deploy. Everything is optional except for the name.

     rails_deploy_extra_services: []
     #rails_deploy_extra_services:
    - name: ''
      changed_state: 'reloaded'
      state: 'started'
      enabled: True

    ---- Log rotation ----

rails_deploy_logrotate_interval

    How often should they be rotated? Accepted values: hourly, daily, weekly, monthly and yearly

    rails_deploy_logrotate_interval: 'weekly'

rails_deploy_logrotate_rotation

    Log files are rotated N times before being removed.

    rails_deploy_logrotate_rotation: 24

    ---- Environment settings ----

    Both the default and custom environment variables will get added together and be written to /etc/default/{{ rails_deploy_service }}.

rails_deploy_default_env

    Default environment variables added to each app.

    rails_deploy_default_env:
      RAILS_ENV: '{{ rails_deploy_system_env }}'
      DATABASE_URL: "{{ rails_deploy_database_adapter }}://{{ rails_deploy_service }}:{{ rails_deploy_database_user_password }}@{{ rails_deploy_database_host }}:{{ rails_deploy_database_port }}/{{ rails_deploy_service }}_{{ rails_deploy_system_env }}?pool={{ rails_deploy_database_pool }}&timeout={{ rails_deploy_database_timeout }}"
      # Application variables, they are used in the backend/worker variables below.
      SERVICE: '{{ rails_deploy_service }}'
      LOG_FILE: '{{ rails_deploy_log }}/{{ rails_deploy_service }}.log'
      RUN_STATE_PATH: '{{ rails_deploy_run }}'
      # Backend variables, they work in conjunction with the example
      # server configs. Check docs/examples/rails/config/puma.rb|unicorn.rb.
      LISTEN_ON: '{{ rails_deploy_backend_bind }}'
      THREADS_MIN: 0
      THREADS_MAX: 16
      WORKERS: 2
      # Background worker variables. Check docs/examples/rails/config/sidekiq.yml
      # and initializers/sidekiq.rb on how use this in your application.
      BACKGROUND_URL: '{{ rails_deploy_worker_url }}'
      BACKGROUND_THREADS: '{{ rails_deploy_database_pool }}'

rails_deploy_env

    Custom environment variables added to a specific app.

    rails_deploy_env: {}

    ---- Nginx settings ----

rails_deploy_nginx_server_enabled

    Should nginx be enabled?

    rails_deploy_nginx_server_enabled: True

rails_deploy_nginx_domains

    What domain names should the app be associated to?

    rails_deploy_nginx_domains: ['{{ ansible_fqdn }}']

    If you want to edit any of the values for nginx below, you will need to copy the whole variable over even if you need to edit 1 value.

    Consult the debops.nginx documentation if needed.

rails_deploy_nginx_upstream

    Configure the upstream.

    rails_deploy_nginx_upstream:
      enabled: '{{ rails_deploy_nginx_server_enabled }}'
      name: '{{ rails_deploy_service }}'
      server: "{{ 'unix:' + rails_deploy_backend_bind if not ':' in rails_deploy_backend_bind else rails_deploy_backend_bind }}"

rails_deploy_nginx_server

    Configure the sites-available.

    rails_deploy_nginx_server:
      enabled: '{{ rails_deploy_nginx_server_enabled }}'
      name: '{{ rails_deploy_nginx_domains }}'
      root: '{{ rails_deploy_src }}/public'
      webroot_create: False
      error_pages:
        '404': '/404.html'
        '422': '/422.html'
        '500': '/500.html'
        '502 503 504': '/502.html'
      location_list:
        - pattern: '/'
          options: |
            try_files $uri $uri/index.html $uri.html @{{ rails_deploy_nginx_upstream.name }};
        - pattern: '~ ^/(assets|system)/'
          options: |
            gzip_static on;
            expires max;
            add_header Cache-Control public;
            add_header Last-Modified "";
            add_header ETag "";
        - pattern: '@{{ rails_deploy_nginx_upstream.name }}'
          options: |
            gzip off;
            proxy_set_header   X-Forwarded-Proto $scheme;
            proxy_set_header   Host              $http_host;
            proxy_set_header   X-Real-IP         $remote_addr;
            proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
            proxy_redirect     off;
            proxy_pass         http://{{ rails_deploy_nginx_upstream.name }};

    Usage examples:

    ---- Bare minimum ----

    #rails_deploy_git_location: 'git@github.com:yourname/mycoolapp.git'

    ---- Use a custom service name ----

    #rails_deploy_service: 'myawesomeapp'

    ---- Use a tag or branch instead of master ----

    #rails_deploy_git_version: 'v0.1.0'

    ---- Use mysql instead of postgres ----

    #rails_deploy_database_adapter: 'mysql'

    ---- Use puma instead of unicorn ----

    #rails_deploy_backend: 'puma'

    ---- Enable the background worker ----

    #rails_deploy_worker_enable: True

    ---- Listen on a tcp port instead of a socket ----

    #rails_deploy_backend_bind: '{{ ansible_fqdn }}:8080'

    ---- Deploy to staging instead of production ----

    #rails_deploy_system_env: 'staging'

COPYRIGHT

debops.rails_deploy - Deploy Rails applications using Ansible
Copyright (C) 2014      Nick Janetakis <nickjanetakis@gmail.com>
Copyright (C) 2014-2019 Maciej Delmanowski <drybjed@gmail.com>
Copyright (C) 2015-2019 DebOps Project <http://debops.org/>
SPDX-License-Identifier: GPL-3.0-only
This Ansible role is part of DebOps.
DebOps is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3, as
published by the Free Software Foundation.
DebOps is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DebOps. If not, see https://www.gnu.org/licenses/.

AUTHOR
Nick Janetakis, Maciej Delmanowski

COPYRIGHT
2014-2024, Maciej Delmanowski, Nick Janetakis, Robin Schneider and others