# How do i specify vars file per env during deploy

**URL:** <https://forum.ansible.com/t/how-do-i-specify-vars-file-per-env-during-deploy/16342>\
**Category:** Ansible Project\
**Created:** [September 25, 2014, 6:58pm UTC](https://forum.ansible.com/t/how-do-i-specify-vars-file-per-env-during-deploy/16342 "2014-09-25T18:58:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Subramanian\_Olagappa](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@Subramanian\_Olagappa](https://forum.ansible.com/u/Subramanian_Olagappa)\
**Post date:** [September 25, 2014, 6:58pm UTC](https://forum.ansible.com/t/how-do-i-specify-vars-file-per-env-during-deploy/16342/1 "2014-09-25T18:58:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Igor\_Homyakov](https://avatars.discourse-cdn.com/v4/letter/i/f4b2a3/32.png) [@Igor\_Homyakov](https://forum.ansible.com/u/Igor_Homyakov)\
**Post date:** [September 26, 2014, 6:32am UTC](https://forum.ansible.com/t/how-do-i-specify-vars-file-per-env-during-deploy/16342/2 "2014-09-26T06:32:29Z")

</div>

Hi Olga,

There are two options:

\* Using vars\_files  
[http://docs.ansible.com/playbooks\_variables.html#variable-file-separation](http://docs.ansible.com/playbooks_variables.html#variable-file-separation)

&nbsp;&nbsp;&nbsp;&nbsp;- hosts: all  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vars\_files:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- "{{ deployment\_env}}.yml"

\* You can keep environment specific variables separately  
[http://docs.ansible.com/intro\_inventory.html#splitting-out-host-and-group-specific-data](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  
&nbsp;&nbsp;&nbsp;&nbsp;└── hosts

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

-- Best, Igor

---

<div class="post-metadata">

**Author:** ![Subramanian\_Olagappa](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@Subramanian\_Olagappa](https://forum.ansible.com/u/Subramanian_Olagappa)\
**Post date:** [September 26, 2014, 2:07pm UTC](https://forum.ansible.com/t/how-do-i-specify-vars-file-per-env-during-deploy/16342/3 "2014-09-26T14:07:13Z")

</div>

Thanks Igor

Regards
