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
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