I am unable to use Ansible localhost (Linux) to connect to a share folder in a Windows server. I am getting "[Errno 2] No such file or directory: b'net'". However, I have checked that my file path to the share folder is correct, so I am not sure how to resolve this error.

The share folder task as written in my playbook:

  - name: Connect to shared folder
    command: net use * '\\10.15.250.110\mixeddocs' /user:{{ username }} {{ password }} /p:no
    become: yes

The full error message:

The full traceback is:
  File "/tmp/ansible_ansible.legacy.command_payload_tjjro3uh/ansible_ansible.legacy.command_payload.zip/ansible/module_utils/basic.py", line 2022, in run_command
    cmd = subprocess.Popen(args, **kwargs)
  File "/usr/lib64/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib64/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
fatal: [localhost]: FAILED! => {
    "changed": false,
    "cmd": "net use '*' '\\\\10.15.250.110\\mixeddocs' /user:newuser Password /p:no",
    "invocation": {
        "module_args": {
            "_raw_params": "net use * '\\\\10.15.250.110\\mixeddocs' /user:newuser Password /p:no",
            "_uses_shell": false,
            "argv": null,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "stdin_add_newline": true,
            "strip_empty_ends": true,
            "warn": false
        }
    },
    "msg": "[Errno 2] No such file or directory: b'net'",
    "rc": 2,
    "stderr": "",
    "stderr_lines": [],
    "stdout": "",
    "stdout_lines": []
}
1

There are 1 best solutions below

2
Ian S. Oberemko On

I'm not quite sure what exactly you are doing but have two suggestions:

  1. If you want to access share from Windows host you should use win_command (ansible.windows collection) with your "net use" command instead of command (ansible.builtin - Linux collection).

  2. If you want to access Windows share from Linux host you should use Linux way to access network directories or just use ansible.posix.mount module.