I’m attempting to execute a PowerShell script on a Windows host to create a Windows Server Failover Cluster. Running the script on node1 works without issue when logged in as a service account with appropriate AD permissions and using a PowerShell terminal ran as Administrator.
Executing the same script via Ansible (using the service account mentioned above) results in an error stating I do not have permissions to edit node1’s registry. Adding the “become” statements below get past this error, but then I receive an error that node2 cannot be added to the cluster as I don’t have permissions to its registry.
This will create an “interactive” token that can delegate it’s credentials to downstream servers as needed. If you don’t specify a password then it will essentially do a “batch” logon without a password similar to running in a scheduled task but without saving the user’s credentials.
If you are running a script then I would say win_shell is easier but neither are truly wrong… Unfortunately error handling in PowerShell is a bit of a mixed bag, by default it sets $ErrorActionPreference = ‘Continue’ which can cause some errors to be “ignored” or at least not part of the final error condition check. I would make sure that you have $ErrorActionPreference = ‘Stop’ in your script to ensure that an error actually stops your script and exits with a non-0 return code or at least throw an exception in the cases where you want a failure to occur.