在“可可”中,如何将角色中的默认字典与传递给该角色的字典作为参数进行组合? [英] In Ansible, how can I combine a default dictionary in a role with a dictionary passed to that role as an argument?

查看:108
本文介绍了在“可可”中,如何将角色中的默认字典与传递给该角色的字典作为参数进行组合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可复制中,我如何组合角色中的默认字典和传递给该角色的字典作为参数

解决方案

作为一个解决方案,请考虑角色 nginx-reverse-proxy



nginx-reverse-proxy / defaults / main.yml :

 code> default_nginx:
application_context:/ {{application_name}} - {{application_component_name}}
reverse_proxy:
port:8080
/ pre>

nginx-reverse-proxy / templates / reverse-proxy.conf

  {%set combined_nginx = default_nginx | combine(nginx,recursive = true) - %} 
location {{combine_nginx.application_context}} {
proxy_pass http:// localhost:{{combined_nginx.reverse_proxy.port}};
proxy_set_header X-Forwarded-Host $ host;
proxy_set_header X-Forwarded-Server $ host;
proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
}

my-nginx-reverse-proxy-meta / main.yml

 依赖关系:
- selfcertification-service
- 角色:nginx-reverse-代理
nginx:{reverse_proxy:{port:8095}}


In Ansible, how can I combine a default dictionary in a role with a dictionary passed to that role as an argument?

解决方案

As a solution by example, consider role nginx-reverse-proxy:

nginx-reverse-proxy/defaults/main.yml:

default_nginx:
  application_context: /{{ application_name }}-{{ application_component_name }}
  reverse_proxy:
    port: 8080

nginx-reverse-proxy/templates/reverse-proxy.conf:

{% set combined_nginx = default_nginx | combine(nginx, recursive=true) -%}
location {{ combined_nginx.application_context }} {
        proxy_pass http://localhost:{{ combined_nginx.reverse_proxy.port }};
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

my-nginx-reverse-proxy-meta/main.yml:

dependencies:
  - selfcertification-service
  - role: nginx-reverse-proxy
    nginx: { reverse_proxy: { port: 8095 } }

这篇关于在“可可”中,如何将角色中的默认字典与传递给该角色的字典作为参数进行组合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆