我有一个 Azure RM 模板(WindowsVirtualMachine.json
和 WindowsVirtualMachine.parameters.json
),我可以使用以下 YML 通过 Ansible 进行部署:
---
- name: Deploy Azure ARM template.
hosts: localhost
connection: local
gather_facts: false
tasks:
- name: Create Azure Deploy
azure_rm_deployment:
state: present
resource_group_name: AnsibleTest
location: UK South
template: "{{ lookup('file', 'WindowsVirtualMachine.json') }}"
parameters: "{{ (lookup('file', 'WindowsVirtualMachine.parameters.json') | from_json).parameters }}"
我试图找出是否可以引用 2 个参数位置;一个来自 JSON,另一个来自 Ansible YML 文件。如:
template: "{{ lookup('file', 'WindowsVirtualMachine.json') }}"
parameters: "{{ (lookup('file', 'WindowsVirtualMachine.parameters.json') | from_json).parameters }}"
adminPassword:
value: "Password123"
我问的原因是询问我是否可以将 adminPassword
值放入 Ansible Vault 中,以免被窥探。
我是编码新手,遗憾的是 Google 没有给我带来任何乐趣。任何建议将不胜感激。
最佳答案
将密码保存到受 Ansible Vault 保护的变量中,例如
adminPassword_define_in_vault
将参数文件转换为模板,即将其重命名为
WindowsVirtualMachine.parameters.json.j2
修改上面的模板,使其包含:
"adminPassword": { "value": "{{ adminPassword_defined_in_vault }}" },
在剧本中使用
template
查找插件而不是file
:parameters: "{{ (lookup('template', 'WindowsVirtualMachine.parameters.json.j2')).parameters }}"
关于json - Ansible azure_rm_deployment 引用来自 2 个位置的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46545902/