0

我有一个可靠的 tomcat 角色

默认值/main.yml

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

我有另一个角色(应用程序),它使用 tomcat 角色作为依赖项,如下所示

默认值/main.yml

app_uriencoding: "ISO-8859-1"

元/main.yml

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

当我在目标上运行应用程序角色时,我希望将应用程序角色 (ISO-8859-1) 中定义的 URIEncoding 值传递给 tomcat 角色并覆盖 uriencoding 的 tomcat 角色默认值。

我无法将值传递给 tomcat 角色' {{ tomcat_http.URIEncoding }}。我尝试过的一些选项

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

要么我收到语法错误,要么就是不起作用。如果有人对如何将值传递给映射变量有任何想法,请告诉我。

4

1 回答 1

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"
于 2017-12-12T18:42:35.327 回答