ansible模块azure.azcollection在windows目标上一直失败

92vpleto  于 2023-04-12  发布在  Windows
关注(0)|答案(1)|浏览(117)

我想使用azure.azcollection从Azure存储帐户下载blob。这在我的剧本中。来自https://learn.microsoft.com/en-us/azure/developer/ansible/key-vault-configure-secrets?tabs=ansible的示例使用localhost

- hosts: all
  tasks:
    - name: Download the file
      azure.azcollection.azure_rm_storageblob:
        resource_group: 'myRG'
        storage_account_name: 'mySA'
        container: mycontainer
        blob: 'folder/file.txt'
        dest: 'C:\Temp\folder\file.txt'
      delegate_to: localhost

并且localhost通过winrm连接并且连接被拒绝。

azure-arm.azure_image:     "changed": false,
   azure-arm.azure_image:     "msg": "ssl: HTTPSConnectionPool(host='localhost', port=5986): Max retries exceeded with url: /wsman (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f42dc0618e0>: Failed to establish a new connection: [Errno 111] Connection refused'))",
   azure-arm.azure_image:     "unreachable": true
   azure-arm.azure_image: }

我一直在寻找解决方案,但我找不到在Windows VM上工作的示例。我知道这可以用PowerShell完成,但我被要求使用Ansible。

osh3o9ms

osh3o9ms1#

msg": "ssl: HTTPSConnectionPool(host='localhost', port=5986): Max retries exceeded with url: /wsman (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f42dc0618e0>: Failed to establish a new connection: [Errno 111] Connection refused'))",

从ansible主机连接到Windows VM时,我收到了相同的错误,请参阅下面:-

为了解决这个错误,请使用下面的代码创建一个新的yml文件:

- hosts: all

vars_prompt:

- name: ansible_password

prompt: "Enter local administrator password"

vars:

ansible_user: siliconuser

ansible_connection: winrm

ansible_winrm_transport: ntlm

ansible_winrm_server_cert_validation: ignore

tasks:

- name: Test connection

win_ping:

在您的ansible主机中运行以下命令以连接到Windows VM:-

ansible-playbook connect_windows_vm.yml -i 20.49.178.48,

输出:-成功连接到VM,如下所示:-

确保目标VM中的winrm已启用,并且已删除防火墙限制。此外,添加入站NSG规则以允许Azure VM中的端口5986,如下所示:-

同时检查VM的防火墙设置,如下所示,以允许入站连接到winrm服务:-

我尝试连接到我的Windows VM并下载Blob,但收到错误,因为Ansible模块在Windows主机上运行时有一定的限制。

作为替代,而不是使用PowerShell,您可以使用azcopy命令行将文件从blob存储下载到本地Windows VM,如下所示:-
az copy命令:-

azcopy copy "https://siliconstrg56.blob.core.windows.net/?sv=xxxx-xx-xxxxxxxxxxxxxxxxxxxxxxxxdlacupiytfx&se=2023-04-12T17:30:12Z&st=2023-04-12T09:30:12Z&spr=https&sig=xxxxxxxxxxxxxxxxxxxxxxxxxxAVdROvKFEd%2F58mE%3D" "C:\folder" --recursive=true

输出:-

入口:-

本地:-

相关问题