Skip to content

Instantly share code, notes, and snippets.

@theotherdon
Created February 9, 2016 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theotherdon/d59aea24cc6633e9893b to your computer and use it in GitHub Desktop.
Save theotherdon/d59aea24cc6633e9893b to your computer and use it in GitHub Desktop.
Sample Ansible playbook using environment variables.
---
- hosts: rails
remote_user: ubuntu
become: yes
become_user: root
vars:
secret_key_base: '{{ SECRET_KEY_BASE }}'
secret_token: '{{ SECRET_TOKEN }}'
db_username: '{{ DB_USERNAME }}'
db_password: '{{ DB_PASSWORD }}'
sendgrid_username: '{{ SENDGRID_USERNAME }}'
sendgrid_password: '{{ SENDGRID_PASSWORD }}'
devise_secret_key: '{{ DEVISE_SECRET_KEY }}'
twilio_account_sid: '{{ TWILIO_ACCOUNT_SID }}'
twilio_auth_token: '{{ TWILIO_AUTH_TOKEN }}'
roles:
- { role: timezone, tags: timezone }
- { role: ntp, tags: ntp }
- { role: firewall, tags: firewall }
- { role: base-deps, tag: base-deps }
- { role: app_user, tags: app_user }
- { role: postgres, tag: postgres }
- { role: nodejs, tags: nodejs }
- { role: passenger, tags: passenger }
- { role: app, tags: app }
# Create a simple bash script to export a variable called ENV_VARS to pass to Ansible:
# #!/bin/bash
# export ENV_VARS="$(cat .env.staging)"
# Usage: . bin/env_vars && ansible-playbook site.yml -i inventories/production --extra-vars $ENV_VARS
@theotherdon
Copy link
Author

Using this style allows you to make use of your current process for managing environment configuration securely (with dotenv, rbenv-vars or the like) without having to use Ansible's Vault module.

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