2016-12-20 52 views
1

combine如何將combine作爲參數傳遞給該角色的字典中的默認字典?在Ansible中,如何將角色中的默認字典與傳遞給該角色的字典作爲參數進行組合?

+0

我覺得這個問題不值得倒票。雖然這個問題實際上沒有問題,但我認爲它仍然是一個有用且完整的示例,說明模板如何將角色中的默認字典與傳遞給該角色的字典組合爲角色參數。 –

+0

我已將原始問題中的示例移至答案。 –

回答

1

如通過實施例中的溶液,考慮作用nginx-reverse-proxy

nginx的-反向代理/默認/ main.yml

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

nginx的-反向代理/模板/反向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; 
} 

我-nginx的,翻領e-proxy-meta/main.yml

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

你也可以在你的劇本中添加一個步驟來明確定義整個劇本: '' - set_fact: combined_nginx:「{{default_nginx | combine(nginx,recursive = true)}} ''' – Bathz

相關問題