Extending beyond modules

Just as on any platform, there may come a time when the exact functionality required is not available from a module. Although writing a custom module (or modifying an existing one) are viable solutions to this, sometimes, a more immediate solution is required. To this end, the win_command and win_shell modules come to the rescuethese can be used to run literal PowerShell commands on Windows. Many examples are available in the official Ansible documentation, but the following code, for example, would create the C:Mastery directory using PowerShell:

    - name: Create a directory using PowerShell
win_shell: New-Item -Path C:Mastery -ItemType Directory

We could even revert to the traditional cmd shell for this task:

    - name: Create a directory using cmd.exe
win_shell: mkdir C:MasteryCMD
args:
executable: cmd

With these pointers, it should be possible to create the desired functionality in just about any Windows environment.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.20.231