MrDuk
MrDuk

Reputation: 18252

Why does ansible think this variable is undefined?

I have the following vars in a all.yml under /group_vars/:

---
global__:

  app_user: root
  app_group: root

  maven_repo:  http://my.endpoint.a
  package_repo:  http://my.endpoint.b

  java:
    sourceUrl: "{{package_repo}}/java/"
    version: 1.8.0_25

However, when I get to the first task that expands this var file, I get the following output:

 FAILED! => {"failed": true, "msg": "ERROR! ERROR! 'package_repo' is undefined"}

Why?

Upvotes: 0

Views: 857

Answers (1)

fishi0x01
fishi0x01

Reputation: 3759

package_repo is defined within the global__ dictionary. Because of that you would need to reference it as {{ global__.package_repo }}, but since you are referencing from within the same dictionary, you will get the error recursive loop detected in template string. You cannot reference from within the same datastructure, however referencing from another datastructure should work.

So you need to define package_repo in another structure in order to reference it inside the global__.java.sourceUrl variable, e.g. the following would work:

package_repo:  http://my.endpoint.b

global__:

  app_user: root
  app_group: root

  maven_repo:  http://my.endpoint.a

  java:
    sourceUrl: "{{package_repo}}/java/"
    version: 1.8.0_25

or

other_map:
  package_repo:  http://my.endpoint.b

global__:

  app_user: root
  app_group: root

  maven_repo:  http://my.endpoint.a

  java:
    sourceUrl: "{{other_map.package_repo}}/java/"
    version: 1.8.0_25

Upvotes: 2

Related Questions