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

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

问题描述

Ansible 中,我如何组合角色中的默认字典与作为参数传递给该角色的字典?

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

推荐答案

作为示例的解决方案,考虑角色 nginx-reverse-proxy:

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 } }

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

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