Ansible multi stage environment

34 views
Skip to first unread message

amsou

unread,
Nov 28, 2020, 11:41:35 AM11/28/20
to Ansible Project
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,

Stefan Hornburg (Racke)

unread,
Nov 28, 2020, 11:51:16 AM11/28/20
to ansible...@googlegroups.com
On 11/28/20 5:41 PM, amsou wrote:
> 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
Racke

>
>
> 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,
>
> --
> 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 <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/f2682791-6bd8-40f4-a7e7-6c83d5c9de72n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/f2682791-6bd8-40f4-a7e7-6c83d5c9de72n%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

OpenPGP_signature

amir soufi

unread,
Nov 29, 2020, 4:31:33 AM11/29/20
to ansible...@googlegroups.com
Thank you :)


You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/PcJaxWhlv-c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d6731aa7-0ddc-f5b6-1bb3-f72772c26fea%40linuxia.de.
Reply all
Reply to author
Forward
0 new messages