Unable to substitute variable inside variable

11 views
Skip to first unread message

Sanjay

unread,
Mar 9, 2020, 9:06:39 AM3/9/20
to Ansible Project
Any idea/comments why this doesn't work?

Installed aversion -  2.9.0


Playbook : test.yml

-
--
 
- name: substitute vars
    hosts
: localhost
    gather_facts
: False

    vars_files
:
     
- "vars.yml"

    tasks
:
     
- name: print vars
        debug
: msg="{{ vars.a }}"





vars.yml


a
: "{{ lookup('env', 'HOME') }}"



Output :


TASK
[print vars] *****************************************************************************************************************************************************************************
ok
: [localhost] => {


   
"msg": "{{ lookup('env', 'HOME') }}"


}


Why it doesn't print the HOME env value?


Thanks

Vladimir Botka

unread,
Mar 9, 2020, 9:47:30 AM3/9/20
to Sanjay, ansible...@googlegroups.com
On Mon, 9 Mar 2020 06:06:39 -0700 (PDT)
Sanjay <sanjay...@gmail.com> wrote:

> Any idea/comments why this doesn't work?
> Installed aversion - 2.9.0
>
> Playbook : test.yml
> --
> - name: substitute vars
> hosts: localhost
> gather_facts: False
> vars_files:
> - "vars.yml"
> tasks:
> - name: print vars
> debug: msg="{{ vars.a }}"
>
> vars.yml
> a: "{{ lookup('env', 'HOME') }}"
>
> Output :
> TASK [print vars]
> ok: [localhost] => {
> "msg": "{{ lookup('env', 'HOME') }}"
> }
>
> Why it doesn't print the HOME env value?

There is no reason toreference "vars". Try

debug: msg="{{ a }}"

HTH,

-vlado

Sanjay

unread,
Mar 9, 2020, 10:00:04 AM3/9/20
to Ansible Project
Thanks, that seems  to be working!
Reply all
Reply to author
Forward
0 new messages