我可以使用 Ansible 创建 Azure 文件共享吗?

Can I create Azure File Share using Ansible?

是否可以使用 Ansible 创建 Azure 存储文件共享?
有一个 Ansible 模块可以创建 Azure 存储帐户,所以我很擅长。
我没有看到文件共享的任何内容。
有一个叫做 azure_rm_resource 的东西,但我无法使用它。
任何输入将不胜感激。

自定义脚本解决方案

如果您需要自定义实现,我建议使用 Azure CLI 开发自定义脚本,然后 运行 在您的 Ansible 剧本中。

例如参考 fileshare.ps1 脚本,内容为 az storage share create --account-name MyAccount --name MyFileShare ...等

文档:https://docs.microsoft.com/en-us/cli/azure/storage/share?view=azure-cli-latest#az_storage_share_create

使用 Ansible 模块的简单解决方案(编辑:目前还不够)

编辑:此解决方案目前仅创建存储帐户,因此在大多数情况下还不够。

azure 命名空间中有一个已实现的 Ansible 模块,名为 azure_rm_storageaccount。请参阅底部的 link。

确保使用 kind 属性 并指定 FileStorage 值。示例:

- name: Create an account with kind of FileStorage
  azure_rm_storageaccount:
    resource_group: souser_resource_group
    name: souser_file_storage
    type: Premium_LRS
    kind: FileStorage
    tags:
      testing: testing

文档: https://docs.ansible.com/ansible/latest/collections/azure/azcollection/azure_rm_storageaccount_module.html

发布我的答案,因为它会对社区中的某个人有所帮助:

最新提交包含此增强功能!

https://github.com/ansible-collections/azure/pull/603/commits/83a6600417faccf56752a8ae5b1e52a0bac37dfb

复制上面 link 中的示例:

- name: Create storage share
  azure_rm_storageshare:
    name: testShare
    resource_group: myResourceGroup
    account_name: testStorageAccount
    state: present
    access_tier: Cool
    quota: 2048
    metadata:
      key1: value1
      key2: value2