0

I have an ansible tomcat role

defaults/main.yml

tomcat_http:
  port: "8080"
  protocol: "HTTP/1.1"
  connectionTimeout: "120000"
  URIEncoding: "UTF-8"

I have another role (app) which uses tomcat role as a dependency and looks like below

defaults/main.yml

app_uriencoding: "ISO-8859-1"

meta/main.yml

dependencies:
  - { role: common, tags: app }
  - { role: tomcat, tomcat_http.URIEncoding: "{{ app_uriencoding }}", tags: app }

When I run the app role on my targets, Im expecting the URIEncoding value defined in the app role (ISO-8859-1) to be passed to the tomcat role and override the tomcat role default value for uriencoding.

Im unable to pass a value into tomcat roles' {{ tomcat_http.URIEncoding }}. Some of the options I have tried

tomcat_http.URIEncoding
tomcat_http[URIEncoding]
tomcat_http.["URIEncoding"]

Either I get syntax errors or it just doesn't work. Please let me know if anybody has any ideas on how to pass a value into a mapped variable.

harnex
  • 953
  • 1
  • 7
  • 8

1 Answers1

1

Generally, this is not possible, because with default (and advised) Ansible configuration variables overrides lower-priority ones.

But there is hash_behavior option, which you can set to merge.

In this case, you can use:

- role: tomcat
  tomcat_http:
    URIEncoding: "{{ app_uriencoding }}"
  tags: app

This way tomcat_http from role's var will be merged with role's defaults. But beware, this can brake some other parts of your playbooks.

If you expect role's defaults to be overriden independently, use:

tomcat_http_port: "8080"
tomcat_http_protocol: "HTTP/1.1"
tomcat_http_connectionTimeout: "120000"
tomcat_http_URIEncoding: "UTF-8"
Konstantin Suvorov
  • 65,183
  • 9
  • 162
  • 193