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

powershell_script resource erroneously indicates password not provided #8334

Open
Blorpy opened this Issue Apr 1, 2019 · 0 comments

Comments

Projects
None yet
2 participants
@Blorpy
Copy link

Blorpy commented Apr 1, 2019

Description

When passing a user to a powershell_script block, I also provide a password, but chef-client errors with: powershell_script[Guard resource] (dynamically defined) had an error: Mixlib::ShellOut::InvalidCommandOption: You must supply a password when supplying a user in windows

Chef Version

14.11.21

Platform Version

Windows 10

Replication Case

Have a powershell_script resource block with a guard, and a user and password declaration.

Client Output

================================================================================
Error executing action `run` on resource 'powershell_script[Add admins to SeNetworkLogonRight access]'
================================================================================

Mixlib::ShellOut::InvalidCommandOption
--------------------------------------
powershell_script[Guard resource] (dynamically defined) had an error: Mixlib::ShellOut::InvalidCommandOption: You must supply a password when supplying a user in windows

Resource Declaration:
---------------------
# In C:/chef/cache/cookbooks/systems/recipes/windows_access_conf.rb

 32:     powershell_script "Add #{group} to #{right} access" do
 33:       code <<-EOH
 34:       import-module "#{node['windows']['psmodules']['path']}/userrights/#{node['windows']['psmodules']['userrights']['version']}/uesrrights.psm1"
 35:       Grant-UserRight -Account 'DOMAIN\#{group}' -Right #{right}
 36:       EOH
 37:       user 'domain_read_only.gen'
 38:       domain 'DOMAIN'
 39:       password ChefVault::Item.load("credentials","domain_read_only.gen")["password"]
 40:       sensitive false
 41:       not_if "$(import-module '#{node['windows']['psmodules']['path']}/userrights/#{node['windows']['psmodules']['userrights']['version']}/uesrrights.psm1'; $?) -and $(Get-AccountsWithUserRight -Right #{right}|findstr /I /B #{group}; $?)"
 42:     end
 43:   end
 44: end

Compiled Resource:
------------------
# Declared in C:/chef/cache/cookbooks/systems/recipes/windows_access_conf.rb:32:in `block (2 levels) in from_file'

powershell_script("Add admins to SeNetworkLogonRight access") do
  action [:run]
  default_guard_interpreter :powershell_script
  command nil
  backup 5
  interpreter "powershell.exe"
  declared_type :powershell_script
  cookbook_name "systems"
  recipe_name "windows_access_conf"
  code "      import-module \"C:/Program Files/WindowsPowerShell/Modules/userrights/2.1.07/uesrrights.psm1\"\n      Grant-UserRight -Account 'DOMAIN\#{group}' -Right SeNetworkLogonRight\n"
  domain "DOMAIN"
  user "domain_read_only.gen"
  password "*sensitive value suppressed*"
  sensitive false
  not_if "$(import-module 'C:/Program Files/WindowsPowerShell/Modules/userrights/2.1.07/uesrrights.psm1'; $?) -and $(Get-AccountsWithUserRight -Right SeNetworkLogonRight|findstr /I /B admins; $?)"
end

System Info:
------------
chef_version=14.11.21
platform=windows
platform_version=10.0.17134
ruby=ruby 2.5.3p105 (2018-10-18 revision 65156) [x64-mingw32]
program_name=C:/opscode/chef/bin/chef-client
executable=C:/opscode/chef/bin/chef-client


Running handlers:
[2019-04-01T17:08:44-06:00] ERROR: Running exception handlers
Running handlers complete
[2019-04-01T17:08:44-06:00] ERROR: Exception handlers complete
Chef Client failed. 1 resources updated in 18 seconds
[2019-04-01T17:08:44-06:00] FATAL: Stacktrace dumped to C:/chef/cache/chef-stacktrace.out
[2019-04-01T17:08:44-06:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2019-04-01T17:08:44-06:00] FATAL: Mixlib::ShellOut::InvalidCommandOption: powershell_script[Add admins to SeNetworkLogonRight access] (systems::windows_access_conf line 32) had an error: Mixlib::ShellOut::InvalidCommandOption: powershell_script[Guard resource] (dynamically defined) had an error: Mixlib::ShellOut::InvalidCommandOption: You must supply a password when supplying a user in windows

Stacktrace

Mixlib::ShellOut::InvalidCommandOption: powershell_script[Add ampeng-lab-admins to SeNetworkLogonRight access] (systems::windows_access_conf line 32) had an error: Mixlib::ShellOut::InvalidCommandOption: powershell_script[Guard resource] (dynamically defined) had an error: Mixlib::ShellOut::InvalidCommandOption: You must supply a password when supplying a user in windows
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/mixlib-shellout-2.4.4-universal-mingw32/lib/mixlib/shellout/windows.rb:36:in `validate_options'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/mixlib-shellout-2.4.4-universal-mingw32/lib/mixlib/shellout.rb:366:in `validate_options'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/mixlib-shellout-2.4.4-universal-mingw32/lib/mixlib/shellout.rb:359:in `parse_options'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/mixlib-shellout-2.4.4-universal-mingw32/lib/mixlib/shellout.rb:184:in `initialize'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/mixin/shell_out.rb:231:in `new'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/mixin/shell_out.rb:231:in `shell_out_command'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/mixin/shell_out.rb:200:in `shell_out_compacted!'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/mixin/shell_out.rb:124:in `shell_out!'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/provider/execute.rb:58:in `block in action_run'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/mixin/why_run.rb:51:in `add_action'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/provider.rb:227:in `converge_by'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/provider/execute.rb:56:in `action_run'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/provider/script.rb:64:in `action_run'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/provider/windows_script.rb:57:in `action_run'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/provider/powershell_script.rb:35:in `action_run'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/provider.rb:182:in `run_action'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/resource.rb:578:in `run_action'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/guard_interpreter/resource_guard_interpreter.rb:74:in `block in evaluate_action'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/guard_interpreter/resource_guard_interpreter.rb:74:in `each'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/guard_interpreter/resource_guard_interpreter.rb:74:in `evaluate_action'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/guard_interpreter/resource_guard_interpreter.rb:60:in `evaluate'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/resource/conditional.rb:99:in `evaluate_command'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/resource/conditional.rb:95:in `evaluate'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/resource/conditional.rb:88:in `continue?'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/resource.rb:1523:in `block in should_skip?'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/resource.rb:1522:in `each'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/resource.rb:1522:in `find'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/resource.rb:1522:in `should_skip?'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/resource.rb:577:in `run_action'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/runner.rb:70:in `run_action'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/runner.rb:98:in `block (2 levels) in converge'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/runner.rb:98:in `each'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/runner.rb:98:in `block in converge'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/resource_collection/resource_list.rb:94:in `block in execute_each_resource'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:114:in `call_iterator_block'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:103:in `iterate'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/resource_collection/resource_list.rb:92:in `execute_each_resource'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/runner.rb:97:in `converge'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/client.rb:720:in `block in converge'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/client.rb:715:in `catch'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/client.rb:715:in `converge'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/client.rb:754:in `converge_and_save'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/client.rb:286:in `run'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/application.rb:303:in `run_with_graceful_exit_option'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/application.rb:279:in `block in run_chef_client'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/local_mode.rb:44:in `with_server_connectivity'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/application.rb:261:in `run_chef_client'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/application/client.rb:479:in `sleep_then_run_chef_client'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/application/client.rb:468:in `block in interval_run_chef_client'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/application/client.rb:467:in `loop'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/application/client.rb:467:in `interval_run_chef_client'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/application/client.rb:451:in `run_application'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/lib/chef/application.rb:66:in `run'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.11.21-universal-mingw32/bin/chef-client:25:in `<top (required)>'
C:/opscode/chef/bin/chef-client:74:in `load'
C:/opscode/chef/bin/chef-client:74:in `<main>'

Is the guard not being passed the password, and only the user?

set_guard_inherited_attributes(
:cwd,
:environment,
:group,
:user,
:umask
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.