How do i specify vars file per env during deploy

75 views
Skip to first unread message

olga

unread,
Sep 25, 2014, 2:58:25 PM9/25/14
to ansible...@googlegroups.com
Hi,

I have a play book to deploy the DB scripts. I also have multiple env like dev,qa & prod. The deployment has a template with few variables like db_user_name and password. I have created the vars file for each env and inventory hosts per env. How do I specify the vars file based on the env I'm deploying. Do we have option to specify the vars file in command line option.

Sorry, if this is a silly question.

Thanks,
olga

Igor Homyakov

unread,
Sep 26, 2014, 7:58:12 AM9/26/14
to ansible...@googlegroups.com
Hi Olga,

There are two options:

* Using vars_files
http://docs.ansible.com/playbooks_variables.html#variable-file-separation

- hosts: all
vars_files:
- "{{ deployment_env}}.yml"

* You can keep environment specific variables separately
http://docs.ansible.com/intro_inventory.html#splitting-out-host-and-group-specific-data

inventory
├── production
│ ├── group_vars
│ │ ├── all
│ │ │ ├── common.yml <- variables for all productions servers
│ │ │ └── secret.yml <- secrets for production
│ │ └── db
│ │ ├── common.yml <- variables for static-ip group
│ │ └── secret.yml <- secrets for static-ip group in production env
│ └── hosts <- inventory file production
├── staging
│ ├── group_vars
│ │ └── all
│ │ └── common.yml
│ └── hosts <- inventory file for staging
└── development
└── hosts

Please have a look at awesome presentations
https://speakerdeck.com/slok/ansible-all-the-things pages 120-127
specifically


-- Best, Igor
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/4075c459-f2f7-4424-96d8-c53cc66f2489%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Subramanian Olagappan

unread,
Sep 26, 2014, 10:07:24 AM9/26/14
to ansible...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages