Skip to content

Ansible role to deploy common configuration files and values for rails

Notifications You must be signed in to change notification settings

oozou/ansible-deploy-rails-env-vars

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ansible-deploy-rails-env-vars

A role to deploy new env vars for configuring a rails app by interpolating values into template files and uploading them to servers.

INSTALLATION

Using ansible-galaxy:

$ ansible-galaxy install oozou.deploy-rails-env-vars

Using requirements.yml:

- src: oozou.deploy-rails-env-vars
  path: roles/
  name: oozou.deploy-rails-env-vars

INTRODUCTION

In the spirit of 12 Factor Apps recommendation for configuring apps, this ansible role provides mechanisms to manage the following commonly used rails configuration files. You can use ansible-vault to encrypt configuration key/values.

This is created to be used with capistrano and symlinked config files from a shared directory for config files.

CONFIGURATION FILES SUPPORTED

EXAMPLE PLAYBOOK

- name: Playbook to deploy rails related configuration files to rails app servers
  hosts: rails_app_servers
  roles:
    - role: oozou.deploy-rails-env-vars
      deploy_rails_config_dir: /path/to/shared/capistrano/config/dir
      etc_environment:
        deploy: true
        template: /local/path/to/your/etc/environment.j2
        dest: /etc/environment
      secrets_yml:
        deploy: true
        template: /local/path/to/your/secrets.yml.j2
        dest: /server/path/to/put/secrets.yml
      application_yml:
        deploy: true
        template: /local/path/to/your/application.yml.j2
        dest: /server/path/to/put/application.yml
      dot_rbenv_vars:
        deploy: true
        template: /local/path/to/your/dot.rbenv-vars.j2
        dest: /server/path/to/put/.rbenv-vars
        create_symlink: true
        symlink_dest: /server/path/to/create/symlink/to/.rbenv-vars
        symlink_owner: username
        symlink_group: group
      database_yml:
        deploy: true
        template: /local/path/to/your/database.yml.j2
        dest: /server/path/to/put/database.yml
      newrelic_yml:
        deploy: true
        template: /local/path/to/your/newrelic.yml.j2
        dest: /server/path/to/put/newrelic.yml

ONE FILE CONFIG

If you really want to use just one file to config your app, you can probably get away with using .rbenv-vars and only deploy this one file. In order for this to work, you will have to setup rbenv on your server for the user that puma (and sidekiq) run as. You will have to have to also write all your configuration files (application.yml, database.yml, etc) to refer to ENV.

The main benefit of doing it this way is that you only have to deploy one file and you can check in all the other configuration files (assuming they refer to the ENV variables) into the repository.

USING WITH CAPISTRANO AND SYMLINKED CONFIG FILES

You can deploy config files that have the configuration values interpolated into configuration files.

Be sure to setup capistrano to use :linked_files and :linked_dirs to symlink the files deployed by ansible and this role to the rails app deploy directory.

WHY IS .rbenv-vars TREATED DIFFERENTLY?

The reason that .rbenv-vars can be configured to be symlinked is because the author usually has the destination be the shared directory so it is in the same directory as all the other configuration files. However, capistrano cannot symlink the .rben-vars to the $HOME directory because it's not in the app directory. Ansible is used to create the symlink from the shared directory to the home directory.

For example:

$ ln -s /home/deploy_user/apps/your_app/shared/dot.rbenv-vars /home/deploy_user/.rbenv-var

ADDITIONAL READING & REFERENCE

AUTHOR

Rick Apichairuk

About

Ansible role to deploy common configuration files and values for rails

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published