【发布时间】:2017-08-19 01:00:39
【问题描述】:
我正在使用 Ansible 创建一个 Azure RM 存储帐户,我想获取访问密钥的值以供以后在模板中使用。这些值在 Azure 端生成。例如,我可以使用 PowerShell Get-AzureStorageKey cmdlet 获取它们。
但是,azure_rm_storageaccount module 的返回值和使用 azure_rm_storageaccount_facts module 收集的事实都不包含这些键。
我想我可以使用 REST API 调用(每个 this answer)来获取它们,但我必须为此任务创建一个 OAuth2 令牌。对于 REST API,可能无法使用为 Ansible 定义的一组凭据(即环境变量 AZURE_CLIENT_ID、AZURE_SECRET、AZURE_SUBSCRIPTION_ID、AZURE_TENANT)。
有没有办法获取这些密钥(使用已经提供给 Ansible 的凭据)?
事实上,Ansible 库似乎包含 the code for fetching these keys,但它们似乎也只在内部使用。
我的剧本:
---
- hosts: localhost
connection: local
vars:
resource_group_name: fetchtest01
resource_group_location: southcentralus
storage_account: fdsahf343u2s
storage_account_type: Standard_LRS
tasks:
- name: Ensure resource group "{{ resource_group_name }}" exists
azure_rm_resourcegroup:
name: "{{ resource_group_name }}"
location: "{{ resource_group_location }}"
- name: Ensure storage account "{{ storage_account }}" exists in "{{ resource_group_name }}" resource group
azure_rm_storageaccount:
resource_group: "{{ resource_group_name }}"
name: "{{ storage_account }}"
account_type: "{{ storage_account_type }}"
- name: Fetch storage account keys
# fetch storage_account_keys
- name: Use the storage_account_keys.primary in a template
template:
# ...
【问题讨论】: