# Ansible multi stage environment

**URL:** <https://forum.ansible.com/t/ansible-multi-stage-environment/34252>\
**Category:** Ansible Project\
**Created:** [November 28, 2020, 4:41pm UTC](https://forum.ansible.com/t/ansible-multi-stage-environment/34252 "2020-11-28T16:41:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![amir\_soufi](https://avatars.discourse-cdn.com/v4/letter/a/82dd89/32.png) [@amir\_soufi](https://forum.ansible.com/u/amir_soufi)\
**Post date:** [November 28, 2020, 4:41pm UTC](https://forum.ansible.com/t/ansible-multi-stage-environment/34252/1 "2020-11-28T16:41:34Z")

</div>

Ho fols,

I was wondering if anyone could advise on how I can manage multi environment variables using ansible. Imagine i have development and staging. I have the following structure:

.  
├── inventories  
│ ├── development  
│ │ ├── group\_vars  
│ │ │ └── all.yml  
│ │ └── hosts  
│ └── staging  
│ ├─── group\_vars  
│ │ └── all.yml  
│ │ └── hosts  
├── roles  
└── test.yml

In each all.yml file, i have one variable like this:

vars:  
name:“development”

I was wondering how is the best approach to load the values depending on a parameter to set for example on command line (-i env=development).

In test.yml, I have this:

- name: test playbook

hosts: localhost  
connection: local

tasks:

- name:  
debug:  
var: name

When I execute, I get this:

ansible-playbook -i inventories/development/ test.yml -vvv  
…  
ok: [localhost] =\> {  
“name”: “VARIABLE IS NOT DEFINED!: ‘name’ is undefined”  
}

I’m kind of new to ansible and I’ve found thousands of different ways and I was wondering what is the best approach? Because I’m kind of lost ☹ ☹

Regards,

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [November 28, 2020, 4:50pm UTC](https://forum.ansible.com/t/ansible-multi-stage-environment/34252/2 "2020-11-28T16:50:41Z")

</div>

> Ho fols,
> 
> I was wondering if anyone could advise on how I can manage multi environment variables using ansible. Imagine i have  
> development and staging. I have the following structure:
> 
> .  
> ├── inventories  
> │ ├── development  
> │ │ ├── group\_vars  
> │ │ │ └── all.yml  
> │ │ └── hosts  
> │ └── staging  
> │ ├─── group\_vars  
> │ │ └── all.yml  
> │ │ └── hosts  
> ├── roles  
> └── test.yml
> 
> In each all.yml file, i have one variable like this:
> 
> vars:  
> name:"development"

It should be

name: "development"

as this file is only for variables and therefore "vars: " is not needed.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![amir\_soufi](https://avatars.discourse-cdn.com/v4/letter/a/82dd89/32.png) [@amir\_soufi](https://forum.ansible.com/u/amir_soufi)\
**Post date:** [November 29, 2020, 9:31am UTC](https://forum.ansible.com/t/ansible-multi-stage-environment/34252/3 "2020-11-29T09:31:00Z")

</div>

Thank you 🙂
