使用ansible上传到azure文件共享而无需安装

Upload to azure file share using ansible without mounting

我有一个 azure storage account,其中我有一个 azure file share。现在我正在将它安装在服务器上并在那里上传文件,ansible 中是否有一种方法可以直接将文件提取并上传到 azure share 而不是将其安装在服务器上然后执行相同的操作?我在 azure_rm_storageaccount 中搜索过它,但除了 mounting 之外找不到任何其他想法。如有任何帮助,我们将不胜感激。

不幸的是,无法通过 Ansible 提供的模块直接上传文件。特殊模块当前不存在。所以你需要另想办法通过Ansible来实现。

例如,您可以使用 Azure CLI 命令 azure storage file upload 将文件上传到 Azure 文件存储:

az storage file upload --account-key 00000000 --account-name MyStorageAccount --path path/file.txt --share-name MyShare --source /path/to/file

然后你可以像这样用 shell module 把这个命令放在 ansible 中:

tasks:
  - name: Get all the access keys
    shell: aws iam list-access-keys --user-name {{ username }} --query 'AccessKeyMetadata[*].AccessKeyId'