Ansible – Create a new directory on a CIFS shared folder

In this post, I will show you how to create a directory on a CIFS shared folder hosted on the Windows machine

This task can be achieved by configuring the WinRM listener on the Windows machine. In the playbook, we will communicate with the listener using CredSSP. The TCP port is defined on 5986 (WinRM default port for HTTPS listener)

You can find here a documentation on how to configure this WinRM listener

---
- hosts: myWindowsNode
  vars:
    ansible_user: mywinusername
    ansible_password: Password    
    ansible_port: 5986
    ansible_connection: winrm
    ansible_winrm_transport: credssp
    ansible_winrm_server_cert_validation: validate

  tasks:
  - name: create the folder called "TheNewFolder"
    win_file:
      path: "//myFileSEerver01/MySharedFolder/TheNewFolder"
      state: directory

Ansible – Create a new directory on a CIFS shared folder

4 thoughts on “Ansible – Create a new directory on a CIFS shared folder

  • September 17, 2019 at 9:17 am
    Permalink

    i facing error while running this module.
    can you please help.
    ERROR :
    « module_stderr »: « An error occurred while creating the pipeline.\r\n + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordE \r\n xception\r\n + FullyQualifiedErrorId : RuntimeException\r\n \r\nException calling \ »Run\ » with \ »1\ » argument(s): \ »Exception calling \ »Invoke\ » with \r\n\ »0\ » argument(s): \ »The running command stopped because the preference variable \r\n\ »ErrorActionPreference\ » or common parameter is set to Stop: Access is denied\ »\ »\r\nAt line:47 char:5\r\n+ $output = $entrypoint.Run($payload)\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordE \r\n xception\r\n + FullyQualifiedErrorId : ScriptMethodRuntimeException\r\n \r\n », « module_stdout »: «  », « msg »: « MODULE FAILURE », « rc »: 1}

    Reply
    • September 17, 2019 at 8:26 am
      Permalink

      Hello Saradhi, you have an access denied error. You have to check if the ansible user you use, have the correct permissions to create the folder.

      Reply
  • September 17, 2019 at 9:17 am
    Permalink

    i facing error while running this module.
    can you please help.
    ERROR :
    « module_stderr »: « An error occurred while creating the pipeline.\r\n + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordE \r\n xception\r\n + FullyQualifiedErrorId : RuntimeException\r\n \r\nException calling \ »Run\ » with \ »1\ » argument(s): \ »Exception calling \ »Invoke\ » with \r\n\ »0\ » argument(s): \ »The running command stopped because the preference variable \r\n\ »ErrorActionPreference\ » or common parameter is set to Stop: Access is denied\ »\ »\r\nAt line:47 char:5\r\n+ $output = $entrypoint.Run($payload)\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordE \r\n xception\r\n + FullyQualifiedErrorId : ScriptMethodRuntimeException\r\n \r\n », « module_stdout »: «  », « msg »: « MODULE FAILURE », « rc »: 1}

    Reply
    • September 17, 2019 at 8:26 am
      Permalink

      Hello Saradhi, you have an access denied error. You have to check if the ansible user you use, have the correct permissions to create the folder.

      Reply

Leave a Reply to Nicolas HAHANG Cancel reply

Your email address will not be published.