Trying to use ansible to Deploy 22H2, but my powershell script doesn't run on my target computer - ansible

I made an Ansible script to push out Windows 10 22H2 and I have the exe but anytime I try running this:
- name: Install 22H2 using powershell
ansible.windows.win_powershell:
script: C:\Temp\Windows10Upgrade9252.exe /skipeula /quietinstall /auto upgrade
Ansible just runs through the script and the PowerShell doesn't run. Yes I set my execution policy and no I don't get any errors back, again it just runs through it.
Also, when I run this script on the target computer in its own PowerShell session, it works great.
I also tried creating a script with that PowerShell command and then putting it on the target's C drive and then using the PowerShell module to run it, but to no avail.

Related

Using WSL2 to execute jenkins scripts made for linux nodes

We have been using linux test bots so far in Jenkins and have made groovy scrpts that call bash scripts to execute tests. Now we need to add Windows test bots to the pool but we cant start WSL from the script.
Is there any way to use WSL instead of bat / powershell to run bash commands in jenkins pipelines?
using for example wsl -l or wsl + one command works, but just executing the command wsl from the code does not give any error.
Manually triggering wsl from cmd / powershell on the device directly works without any issues.

bash.exe not working on Jenkins (Windows)

When running a build under "Execute Windows batch command" with the "C:\Windows\System32\bash.exe --version" it fails with the error "exit -1073741819".
If I run the same command on the windows command line on the same machine but locally, it works just fine.
Any inputs on where I am failing? I am trying to avoid using git or cygwin and just keep things equal as when I manually run it.
Prints:

Unable to run cygwin in Windows Docker Container

I've been working with Docker for Windows, attempting to create a Windows Container that can run cygwin as the shell within the container itself. I haven't had any luck getting this going yet. Here's the Dockerfile that I've been messing with.
# escape=`
FROM microsoft/windowsservercore
SHELL ["powershell", "-command"]
RUN Invoke-WebRequest https://chocolatey.org/install.ps1 -UseBasicParsing | Invoke-Expression
RUN choco install cygwin -y
RUN refreshenv
RUN [Environment]::SetEnvironmentVariable('Path', $env:Path + ';C:\tools\cygwin\bin', [EnvironmentVariableTarget]::Machine)
I've tried setting the ENTRYPOINT and CMD to try and get into cygwin, but neither seems to do anything. I've also attached to the container with docker run -it and fired off the cygwin command to get into the shell, but it doesn't appear to do anything. I don't get an error, it just returns to the command prompt as if nothing happened.
Is it possible to run another shell in the Windows Container, or am I just doing something incorrectly?
Thanks!
You don't "attach" to a container with docker run: you start a container with it.
In your case, as seen here, docker run -it is the right approach.
You can try as an entry point using c:\cygwin\bin\bash, as seen in this issue.
As commented in issue 32330:
Don't get me wrong, cygwin should work in Docker Windows containers.
But, it's also a little paradoxical that containers were painstakingly wrought into Windows, modeled on containers on Linux, only for people to then want to run Linux-utils in these newly minted Docker Windows containers...
That same issue is still unresolved, with new case seen in May and June 2018:
We have an environment that compiles with Visual Studio but still we want to use git and some very useful commands taken from linux.
Also we use of-the-shelve utilities (e.g. git-repo) that uses linux commands (e.g. curl, grep,...)
Some builds require Cygwin like ICU (a cross-platform Unicode based globalization library), and worst: our builds require building it from source.
You can see an example of a crash in MSYS2-packages issue 1239:
Step 5/5 : RUN "C:\\msys64\\usr\\bin\\ls.exe"
---> Running in 5d7867a1f8da
The command 'cmd /S /C "C:\\msys64\\usr\\bin\\ls.exe"' returned a non-zero code: 3221225794
This can get more information on the crash:
PS C:\msys64\usr\bin>
Get-EventLog -Index 28,29,30 -LogName "Application" | Format-List -Property *
The workaround was:
PS > xcopy /S C:\Git C:\Git_Copy
PS > C:\Git_Copy\usr\bin\sh.exe --version > v.txt
PS > type v.txt
As mentioned in that thread, the output gets lost somewhere in the container, thus sending it to a text file.
After playing with it for a long time, my findings were the following:
If your Cygwin utilities are crashing your container, you need to use process isolation. See https://learn.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/version-compatibility for the requirements (essentially you need to use Windows Server 2016 and a build-matching Docker Image). I spent some time trying to understand the reason why hyper-v isolation doesn't work and so far I didn't come to any conclusion;
If your Cygwin utilities apparently do nothing - but they don't crash the container - you need to remove the -t flag (the -i flag is still ok) or alternatively play with stdout redirection. Apparently there seems to be an issue with MSYS2 when it deals with some pseudo-ttys. You can verify that programs still run if you redirect stdout to a file (e.g. whoami won't output anything when you run it without any stdout redirection, but whoami > out.txt will output the expected result to a file). It might be possible to fix this by replacing the pseudo-tty but I didn't try it. I suspect that the problem is an invalid handle somewhere inside the MSYS2 libs - as other console apps can print things to the terminal - but I didn't verify this.
Hope it helps to all of you having the same problem.
I was able to get a preinstalled (copied from the host) copy of Cygwin to work in a nanoserver-based container with these two steps:
Using Żubrówka's recommendation for no -t in the docker run cmd-line (when running docker interactively)
Copying the host's (Windows Server 2016) kernel32.dll to the container's c:\windows\system32
I found serveral versions of kernel32.dll on my system, and used the one from c:\windows\system32 with md5 hash d8948a7af764f7153b3e396ad44992ff
This also made a large variety of other executables work. Note that without a tty, using the container is even more cumbersome, and the bash shell doesn't render the prompt. However, scripts (via Jenkins, in my case) that rely on cygwin components work fine.
If that doesn't help, try this guide, it helped me a lot. If your windows application (other than cygwin) is legitimately missing DLLs, the instructions in this guide can help. It never occurred to me that SysInternals' procmon.exe can be run on the host and still report events from the container!

Jenkins not playing nice with a private GitHub repository (Windows)

I cannot for the life of me seem to get my Jenkins CI to work with Github.
I had failure on the clone command, but that was due to keys, so I logged in as service account (the user Jenkins runs under as a Windows Service) and ran the clone command. All good in the hood.
However, when I want to run the fetch to get latest, it won't finish. It just sits there. I have tried via the Git plugin for Jenkins, and also via a Windows commandline script. Neither work. However, if I open a command prompt and type the command in, it works!
So how do I get it to work via Jenkins?
I run this script:
set
"C:\Program Files (x86)\Git\bin\git.exe" fetch -t ssh://git#github.com/OrgName/MyRepo.git +refs/heads/*:refs/remotes/origin/*
exit 0
and it sticks on the fetch command, never exiting.
Does someone have any suggestion?
It looks like msysGit stuck trying to find one of its components, used during fetch operation.
The Git itself not a single executable actually. It's a set of small tools doing their job great only being put together. Running Git on Windows from bash prompt makes it happen, but when you're running via Windows command prompt or in batch-files, the Force may not be with you.
I think you should check wherever you installed msysGit with option "Run Git from Windows Command Prompt". In this case all needed parts of Git will be added to the system PATH variable and git.exe will be able to access it from batch files, thus it should fix your fetch statement.

Run a windows xp bat script remotely from a ubuntu machine

Is it possible to run a windows xp bat script remotely from a ubuntu machine via command line?
This is possible if you have an ssh server running on the WinXP machine. It is trivial to set up such a server if you have installed Cygwin. This is well described here.
Then from an Ubuntu command line (or cron job) you run
ssh user#winxp command
Make sure your .bat has executable permissions.
I think that the technology you are after is WMI. I see that there is an ubuntu package called wmi-client, which you can sudo apt-get install and attempt to you. Some quick searches and I'm unable to find details, but maybe that will get you somewhere....
You would probably use something like remote desktop, and if you did it that way, it would work, but your question isn't very specific

Resources