souser
souser

Reputation: 6120

Can I create Azure File Share using Ansible?

Is it possible to create an azure storage file share using Ansible ?
There is an Ansible module to create Azure Storage Account, so I am good there.
I dont see anything for File Share.
There is something called azure_rm_resource but I have not been able to get it to work with it.
Any input will be appreciated.

Upvotes: 0

Views: 896

Answers (2)

souser
souser

Reputation: 6120

Posting my answer as it will help someone in the community:

The latest commit contains this enhancement !

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

Copying the example from the link above :

- 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

Upvotes: 1

bradib0y
bradib0y

Reputation: 1099

Custom script solution

If you need custom implementation, I would suggest to use Azure CLI for developing a custom script, and then run it in your Ansible playbook.

E.g. reference fileshare.ps1 script with content of az storage share create --account-name MyAccount --name MyFileShare ...etc.

Documentation: https://learn.microsoft.com/en-us/cli/azure/storage/share?view=azure-cli-latest#az_storage_share_create

Simple solution with Ansible module (Edit: not sufficient at the moment)

Edit: this solution only creates the storage account as of now, so it is not sufficient in most scenarios.

There is an Ansible module for this, already implemented, called azure_rm_storageaccount in the azure namespace. See the link in the bottom.

Make sure to use the kind property and specify FileStorage value. Example:

- 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

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

Upvotes: 1

Related Questions