Questions tagged [win-shell]

Use this tag for questions about the ansible.windows.win_shell module, which runs a command via a shell (PowerShell by default) on the target host.

13 questions
1
vote
1 answer

Windows PowerShell is in NonInteractive mode. Read and Prompt

win_shell: | Get-disk Initialize-Disk -Number 2 -PartitionStyle MBR clear-disk -number 2 -removedata -Confirm:$false Initialize-Disk -Number 2 -PartitionStyle MBR new-partition -disknumber 2 -usemaximumsize |…
vik_nag
  • 415
  • 1
  • 5
  • 7
1
vote
1 answer

Why does ansible win_shell module use powershell 5 when powershell 7 is set as the default?

I'm running a packer build of windows using ansible to provision the VM. I connect to the VM via OpenSHH. I have powershell 7 set as the default shell for OpenSSH. When I connect to the VM over ssh on the command line, the banner says PowerShell…
Mike A
  • 500
  • 4
  • 16
1
vote
1 answer

Ansible put in same option command all values of elements of list

OS: W2K16 Server Ansible: 2.9.9 I search the method to put several vars in the winshell command, but this code launch 3 time the winshell command: - name: "ntp conf" win_shell: | 'w32tm /config /manualpeerlist: {{ item }}…
CH06
  • 139
  • 2
  • 14
0
votes
0 answers

ansible win_shell module to run 2 seperate commands

I am trying to have custom print out based on exit status message stored registered like below in ansible role called from main playbook. - name: Check exit status win_shell: findstr /B failed_update_count {{ansible_workdir}}\\super_install.log |…
vinWin
  • 509
  • 1
  • 5
  • 18
0
votes
2 answers

PowerShell {% if %} {% endif %} syntax throws an error

I wrote this PowerShell script: - name: Some name win_shell: | [xml]$myFile = Get-Content "C:\MyFile.xml" $myFile.SelectSingleNode("//some-element").InnerText = "new text" {% if 1 -eq 1 %} …
toffee
  • 47
  • 2
  • 3
  • 9
0
votes
2 answers

Change element text with ansible.windows.win_shell

I try to change an element text, using ansible.windows.win_shell. This is the XML I have: and this is the XML I would like to have: TEXT The win_shell…
toffee
  • 47
  • 2
  • 3
  • 9
0
votes
0 answers

Ansible win_shell printing wrong output

Ansible win_shell/win_command prints logo output instead of actual output of the command: - name: get Ps1 files win_shell: get-ChildItem -path $testFolder -Filter *.ps1 -Recurse -File -Name -Depth 0 register: ps1_files args: …
Codrin
  • 1
0
votes
0 answers

How can I pass a powershell command in Ansible with parameters

I'm having trouble installing this particular agent in win servers through Ansible. - name: "Installing agent {{agent}} and webservices" register: executed_script win_shell: Invoke-Command -ScriptBlock {& cmd /c…
Nahuster
  • 13
  • 6
0
votes
0 answers

Unable to execute ps1 file via win_shell

I deployed Ansible through Azure DevOps to manage Windows servers. I wrote a ps1 (PowerShell) about monitoring DHCP status and this file executes well directly on the server, but when I execute it using playboo, I don't get any results and no errors…
0
votes
1 answer

Capturing or Trimming the right output from the ansible script

Below is my ansible script - - name: To delete files hosts: current gather_facts: true tasks: - name: Check for the right folder win_shell: | if (Test-Path -Path 'C:\Program Files (x86)\MF\LGG\bin') { Write-Output…
RGV
  • 1
  • 1
  • 4
0
votes
1 answer

ansible: run an nsis uninstaller silently

A Windows application has been installed using an NSIS installer on a target machine under C:\Program Files\my_app\. In that folder there is also the uninstaller Uninstall.exe. I'm trying to write an ansible task that will run that uninstaller…
linuxfever
  • 3,763
  • 2
  • 19
  • 43
0
votes
0 answers

Running Powershell script through Ansible is not producing output file

I have a PowerShell script that runs another script from local server fine when executed locally and produces results in a standard text file. However, when I run the same script through Ansible Runbook, no result is produced The PowerShell script…
rp123409
  • 145
  • 3
  • 11
0
votes
0 answers

win shell Check if file exists before delete

I am using this command via ansible to delete old files win_shell: forfiles -p C:\Logs\ -s -m *.log* /D -15 /C "cmd /c del /q @path" How do I make sure to run this only if there is any file matching criteria Found this similar question but it…
Cannon
  • 2,725
  • 10
  • 45
  • 86