Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setup : Throws an exception error when used to gather custom facts for Windows targets. #42

Closed
misra-anshuman opened this issue Apr 1, 2020 · 1 comment · Fixed by #78

Comments

@misra-anshuman
Copy link

SUMMARY

Since Ansible release v2.8.0, the 'setup' module which we use for gathering custom facts ( powershell scripts ) on Windows targets, is failing with exception error.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

setup.ps1

ANSIBLE VERSION
ansible 2.9.6
  config file = /code/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /root/.local/lib/python2.7/site-packages/ansible
  executable location = /root/bin/ansible
  python version = 2.7.5 (default, Dec  4 2019, 17:34:13) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39.0.1)]
CONFIGURATION

OS / ENVIRONMENT
Windows Server 2012 R2 Standard - PowerShell v5.1
Windows Server 2016 Standard - PowerShell v6.0
STEPS TO REPRODUCE

Calling the 'setup' module with 'fact_path:' pointing to 'C:\ansible\facts.d' which has staged PowerShell scripts, throws an exception error. This error is not seen with Ansible =<v2.7.16; this error is seen with Ansible >=v2.8.0.

- name: 'Gather Custom Facts.'
  setup:
    fact_path: 'C:\\ansible\\facts.d\\'
EXPECTED RESULTS

The task should complete without any errors.

ACTUAL RESULTS
The full traceback is:
Exception setting "CursorPosition": "A command that prompts the user failed because the host program or the command type does not support user interaction. Try a host program that supports user interaction, such as the Windows PowerShell Console or Windows PowerShell ISE, and remove prompt-related commands from command types that do not support user interaction, such as Windows PowerShell workflows."
At line:299 char:5
+     Get-CustomFacts -factpath $factpath
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-CustomFacts], SetValueInvocationException
    + FullyQualifiedErrorId : ExceptionWhenSetting,Get-CustomFacts

ScriptStackTrace:
at <ScriptBlock>, <No file>: line 3
at <ScriptBlock>, C:\ansible\facts.d\<script>.ps1: line 2
at Get-CustomFacts, <No file>: line 22
at <ScriptBlock>, <No file>: line 299

System.Management.Automation.SetValueInvocationException: Exception setting "CursorPosition": "A command that prompts the user failed because the host program or the command type does not support user interaction. Try a host program that supports user interaction, such as the Windows PowerShell Console or Windows PowerShell ISE, and remove prompt-related commands from command types that do not support user interaction, such as Windows PowerShell workflows." ---> System.Management.Automation.Host.HostException: A command that prompts the user failed because the host program or the command type does not support user interaction. Try a host program that supports user interaction, such as the Windows PowerShell Console or Windows PowerShell ISE, and remove prompt-related commands from command types that do not support user interaction, such as Windows PowerShell workflows.
   at System.Management.Automation.Internal.Host.InternalHostRawUserInterface.ThrowNotInteractive()
   at System.Management.Automation.Internal.Host.InternalHostRawUserInterface.set_CursorPosition(Coordinates value)
   at CallSite.Target(Closure , CallSite , Object , Hashtable )
   --- End of inner exception stack trace ---
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
   at System.Management.Automation.PSScriptCmdlet.RunClause(Action`1 clause, Object dollarUnderbar, Object inputToProcess)
   at System.Management.Automation.PSScriptCmdlet.DoEndProcessing()
   at System.Management.Automation.CommandProcessorBase.Complete()
fatal: [<windows_target_machine>]: FAILED! => {
    "changed": false,
    "msg": "Unhandled exception while executing module: Exception setting \"CursorPosition\": \"A command that prompts the user failed because the host program or the command type does not support user interaction. Try a host program that supports user interaction, such as the Windows PowerShell Console or Windows PowerShell ISE, and remove prompt-related commands from command types that do not support user interaction, such as Windows PowerShell workflows.\""
}

@misra-anshuman misra-anshuman changed the title setup : Throws an exception error when used to deploy custom facts for Windows targets. setup : Throws an exception error when used to gather custom facts for Windows targets. Apr 1, 2020
@briantist
Copy link
Contributor

As @jborean93 mentioned in your original issue:

For this particular problem we changed the behaviour of PowerShell modules always running with $ErrorActionPreference = 'Stop' whereas before some were set to Continue and errors were just being ignored. The problem you have here really should be fixed in your custom facts script to properly handle errors that it raises and either ignores them or continues to error if you want the end user to see that error and somehow fix it.

The error is popping up from a script in that directory. It seems that before 2.8 the script there would still have been broken, it just would have been ignored.

I recommend you try putting one script at a time in there to see which one is failing, and then if possible post that script.

If you can't post it, maybe try executing it yourself like this:

powershell.exe -NonInteractive myscript.ps1

And see if you can get a better error message with line number.
You might have something in the script that prompts for user input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants