Ansible:用户未对网络共享进行身份验证

问题描述 投票:0回答:1

我无法通过远程连接将文件从网络共享传输到本地服务器上的磁盘。 我正在登录服务器:SERVER02,但是出现权限被拒绝的情况,在SERVER01上使用Wireshark集合,我发现用户凭据和密码未到达。 这很奇怪,因为在 PowerShell 中执行本地 robocopy 命令可以正常工作。 另外,我使用过 Ansible 模块,但它们不起作用,这个模块 ansible.windows.win_powershell 是给我提供最多信息的模块。 以下是执行的代码及其输出:

- name: Copy files from network share folder to Windows server
  hosts: "{{ host_group }}"
  gather_facts: no
  vars:
    ansible_connection: winrm
    ansible_user: "{{ vm_user }}"
    ansible_password: "{{ vm_pass }}"
    ansible_port: 5985
    ansible_winrm_transport: ntlm
    ansible_winrm_server_cert_validation: ignore

  tasks:
    - name: Copia arquivos
      ansible.windows.win_powershell: 
        script: |
          $Username = "{{ vm_user }}"
          $SecurePassword = ConvertTo-SecureString -String "{{ vm_pass }}" -AsPlainText -Force
          $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username, $SecurePassword
          Enter-PSSession -ComputerName "{{ host_group }}" -Credential $Credential
          robocopy \\SERVER01\I$\APP\MONITOR\ \\SERVER02\I$\JOBS\ /COPYALL /MT /E /b /W:5 /R:5

输出执行:

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows
-------------------------------------------------------------------------------

  Started : terca-feira, 10 de outubro de 2023 10:14:27
   Source = \\SERVER01\I$\APP\MONITOR\
     Dest : \\SERVER02\I$\JOBS\

    Files : *.*

  Options : *.* /S /E /COPYALL /B /MT:8 /R:5 /W:5

------------------------------------------------------------------------------

NOTE : Security may not be copied - Source might not support persistent ACLs.

2023/10/10 10:14:27 ERROR 5 (0x00000005) Accessing Source Directory \\SERVER01\I$\APP\MONITOR\
Access is denied.

使用 ansible 在目录之间成功执行复制。

powershell ansible robocopy
1个回答
0
投票

@mclayton,执行了以下命令,我仍然遇到上述相同的错误。

$Username = "user"
$SecurePassword = ConvertTo-SecureString -String "pass" -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username, $SecurePassword
Invoke-Command -ComputerName SERVER01 -Credential $cred -ScriptBlock {
    robocopy \\SERVER01\I$\APP\MONITOR\ \\SERVER02\I$\JOBS\ /COPYALL /MT /E /b /W:5 /R:5
    Invoke-Command -ComputerName SERVER02 -Credential $Using:cred -ScriptBlock {
        robocopy \\SERVER01\I$\APP\MONITOR\ \\SERVER02\I$\JOBS\ /COPYALL /MT /E /b /W:5 /R:5}
}
© www.soinside.com 2019 - 2024. All rights reserved.