ansible-collections / community.windows

Windows community collection for Ansible
https://galaxy.ansible.com/community/windows
GNU General Public License v3.0
206 stars 160 forks source link

The $robocopy variable doesn't exist. Changed cmd output to &robocopy… #547

Closed DevOpsJeremy closed 11 months ago

DevOpsJeremy commented 11 months ago

The $robocopy variable doesn't exist. Changed cmd output to robocopy to match what actually gets run on line 85.

SUMMARY

The cmd property of the output only includes the robocopy arguments but not the robocopy executable itself.

ISSUE TYPE
COMPONENT NAME

win_robocopy

ADDITIONAL INFORMATION

The module currently returns (for example) the following output in the cmd property:

"cmd": " C:\\path\\to\\source\\ C:\\path\\to\\destination\\ /e /l"

The current code for the win_robocopy.ps1 module is as follows:

$result.cmd = "$robocopy $robocopy_opts"

Since no $robocopy variable exists nothing is returned, resulting in an erroneous leading space and incomplete command.

Validation instructions: Run any task using community.windows.win_robocopy and validate the cmd output property.

Before:

{
  "dest": "C:\\path\\to\\destination\\",
  "src": "C:\\path\\to\\source\\",
  "msg": "Files copied successfully!",
  "flags": "",
  "output": [
    "",
    "-------------------------------------------------------------------------------",
    "   ROBOCOPY     ::     Robust File Copy for Windows                              ",
    "-------------------------------------------------------------------------------",
    "",
    "  Started : Friday, December 22, 2023 3:05:13 AM",
    "   Source : C:\\path\\to\\source\\",
    "     Dest : C:\\path\\to\\destination\\",
    "",
    "    Files : *.*",
    "\t    ",
    "  Options : *.* /S /E /DCOPY:DA /COPY:DAT /R:1000000 /W:30 ",
    "",
    "------------------------------------------------------------------------------",
    "",
    "\t  New Dir          0\tC:\\path\\to\\destination\\",
    "\t    New File  \t\t   15185\tfile1.txt",
    "  0%  ",
    "100%  ",
    "",
    "------------------------------------------------------------------------------",
    "",
    "               Total    Copied   Skipped  Mismatch    FAILED    Extras",
    "    Dirs :         1         1         0         0         0         0",
    "   Files :         1         1         0         0         0         0",
    "   Bytes :    88.4 k    88.4 k         0         0         0         0",
    "   Times :   0:00:00   0:00:00                       0:00:00   0:00:00",
    "   Ended : Friday, December 22, 2023 3:05:13 AM",
    ""
  ],
  "purge": false,
  "changed": true,
  "rc": 1,
  "return_code": 1,
  "cmd": " C:\\path\\to\\source\\ C:\\path\\to\\destination\\",
  "recurse": true,
  "_ansible_no_log": false
}

After

{
  "dest": "C:\\path\\to\\destination\\",
  "src": "C:\\path\\to\\source\\",
  "msg": "Files copied successfully!",
  "flags": "",
  "output": [
    "",
    "-------------------------------------------------------------------------------",
    "   ROBOCOPY     ::     Robust File Copy for Windows                              ",
    "-------------------------------------------------------------------------------",
    "",
    "  Started : Friday, December 22, 2023 3:05:13 AM",
    "   Source : C:\\path\\to\\source\\",
    "     Dest : C:\\path\\to\\destination\\",
    "",
    "    Files : *.*",
    "\t    ",
    "  Options : *.* /S /E /DCOPY:DA /COPY:DAT /R:1000000 /W:30 ",
    "",
    "------------------------------------------------------------------------------",
    "",
    "\t  New Dir          0\tC:\\path\\to\\destination\\",
    "\t    New File  \t\t   15185\tfile1.txt",
    "  0%  ",
    "100%  ",
    "",
    "------------------------------------------------------------------------------",
    "",
    "               Total    Copied   Skipped  Mismatch    FAILED    Extras",
    "    Dirs :         1         1         0         0         0         0",
    "   Files :         1         1         0         0         0         0",
    "   Bytes :    88.4 k    88.4 k         0         0         0         0",
    "   Times :   0:00:00   0:00:00                       0:00:00   0:00:00",
    "   Ended : Friday, December 22, 2023 3:05:13 AM",
    ""
  ],
  "purge": false,
  "changed": true,
  "rc": 1,
  "return_code": 1,
  "cmd": "robocopy C:\\path\\to\\source\\ C:\\path\\to\\destination\\",
  "recurse": true,
  "_ansible_no_log": false
}
DevOpsJeremy commented 11 months ago

@jborean93 this is a quick & simple change without any functionality changes/risks so I think it's an easy merge if you agree, since you're the original author.