choria-plugins / shell-agent

Choria Plugin for running arbitrary shell commands
Apache License 2.0
1 stars 2 forks source link

Issue with mco shell run and Puppet 8 #18

Closed mdechiaro closed 1 year ago

mdechiaro commented 1 year ago

The follow error occurs when trying to run mco shell run 'cat /etc/motd' -W fqdn=hostname.domain.com against a Puppet 8.2.0 system. This is using the latest plugin release, mod 'choria-mcollective_agent_shell', '1.0.5'

:statusmsg=>"undefined method `exists?' for File:Class",

Full error is below.

mco shell run 'cat /etc/motd' -W fqdn=hostname.domain.com -v
Discovering hosts using the mc method for 2 second(s) .... 1

 * [ ============================================================> ] 1 / 1

hostname.domain.com: ERROR: #<MCollective::RPC::Result:0x00007fc8b002b770 @agent="shell", @action="run", @results={:sender=>"hostname.domain.com", :statuscode=>5, :statusmsg=>"undefined method `exists?' for File:Class", :data=>{:stdout=>nil, :stderr=>nil, :success=>nil, :exitcode=>nil}}, @_ddl=#<MCollective::DDL::AgentDDL:0x000055804ce58748 @process_aggregate_functions=nil, @entities={"run"=>{:action=>"run", :input=>{:command=>{:prompt=>"Command", :description=>"Command to run", :type=>:string, :default=>nil, :optional=>false, :validation=>".*", :maxlength=>10240}, :user=>{:prompt=>"User", :description=>"User to run command as", :type=>:string, :default=>nil, :optional=>true, :validation=>".*", :maxlength=>1024}, :timeout=>{:prompt=>"Timeout", :description=>"Timeout to wait for the command to complete", :type=>:float, :default=>nil, :optional=>true}}, :output=>{:stdout=>{:description=>"stdout from the command", :display_as=>"stdout", :default=>nil}, :stderr=>{:description=>"stderr from the command", :display_as=>"stderr", :default=>nil}, :success=>{:description=>"did the process exit successfully", :display_as=>"success", :default=>nil}, :exitcode=>{:description=>"exit code of the command", :display_as=>"exitcode", :default=>nil}}, :display=>:always, :description=>"Run a command"}, "start"=>{:action=>"start", :input=>{:command=>{:prompt=>"Command", :description=>"Command to run", :type=>:string, :default=>nil, :optional=>false, :validation=>".*", :maxlength=>10240}, :user=>{:prompt=>"User", :description=>"User to run command as", :type=>:string, :default=>nil, :optional=>true, :validation=>".*", :maxlength=>1024}}, :output=>{:handle=>{:description=>"identifier to a running command", :display_as=>"handle", :default=>nil}}, :display=>:always, :description=>"Spawn a command"}, "status"=>{:action=>"status", :input=>{:handle=>{:prompt=>"Handle", :description=>"Handle of the command", :type=>:string, :default=>nil, :optional=>false, :validation=>"^[0-9a-z\\-]*$", :maxlength=>36}, :stdout_offset=>{:prompt=>"stdout_offset", :description=>"stdout_offset", :type=>:integer, :default=>nil, :optional=>true}, :stderr_offset=>{:prompt=>"stderr_offset", :description=>"stderr_offset", :type=>:integer, :default=>nil, :optional=>true}}, :output=>{:status=>{:description=>"status of the command", :display_as=>"status", :default=>nil}, :stdout=>{:description=>"stdout of the command", :display_as=>"stdout", :default=>nil}, :stderr=>{:description=>"stderr of the command", :display_as=>"stderr", :default=>nil}, :exitcode=>{:description=>"exitcode of the command", :display_as=>"exitcode", :default=>nil}}, :display=>:always, :description=>"Get status of managed command"}, "list"=>{:action=>"list", :input=>{}, :output=>{:jobs=>{:description=>"state of managed jobs", :display_as=>"jobs", :default=>nil}}, :display=>:always, :description=>"Get a list of all running commands"}, "kill"=>{:action=>"kill", :input=>{:handle=>{:prompt=>"Handle", :description=>"Handle of the command", :type=>:string, :default=>nil, :optional=>false, :validation=>"^[0-9a-z\\-]*$", :maxlength=>36}}, :output=>{}, :display=>:always, :description=>"Kill a command by handle"}}, @meta={:name=>"shell", :description=>"Run commands with the local shell", :author=>"Puppet Labs", :license=>"Apache-2.0", :version=>"1.0.5", :url=>"https://github.com/choria-plugins/shell-agent", :timeout=>180}, @usage="", @config=#<MCollective::Config:0x000055804cef19e8 @configured=true, @subscribe=[], @pluginconf={"nrpe.conf_dir"=>"/etc/nrpe.d", "choria.discovery_host"=>"puppetdb.domain.com", "choria.discovery_port"=>"8085", "choria.middleware_hosts"=>"henson.domain.com:4222", "choria.puppetca_host"=>"puppetca.domain.com", "choria.puppetca_port"=>"8140", "choria.puppetdb_host"=>"puppetdb.domain.com", "choria.puppetdb_port"=>"8081", "choria.puppetserver_host"=>"puppet.domain.com", "choria.puppetserver_port"=>"8140", "choria.security.serializer"=>"json", "choria.tasks.wrapper_path"=>"/opt/puppetlabs/puppet/bin/execution_wrapper", "choria.use_srv"=>"false", "puppet.allow_server_override"=>"true", "puppet.resource_allow_managed_resources"=>"true", "puppet.resource_type_blacklist"=>"exec", "puppet.signal_daemon"=>"false", "actionpolicy.allow_unconfigured"=>"0", "actionpolicy.enable_default"=>"0"}, @connector="Nats", @securityprovider="Choria", @factsource="Yaml", @identity="puppetcode.domain.com", @registration="Base", @registerinterval=0, @registration_collective=nil, @registration_splay=false, @classesfile="/var/lib/puppet/state/classes.txt", @rpcaudit=false, @rpcauditprovider="", @rpcauthorization=false, @rpcauthprovider="", @configdir="/etc/choria", @color=true, @configfile="/etc/choria/client.conf", @logger_type="console", @keeplogs=5, @max_log_size=2097152, @rpclimitmethod=:first, @fact_cache_time=300, @loglevel="warn", @logfacility="user", @collectives=["mcollective"], @main_collective="mcollective", @ssl_cipher="aes-256-cbc", @direct_addressing=true, @direct_addressing_threshold=10, @default_discovery_method="mc", @default_discovery_options=[], @ttl=60, @mode=:client, @publish_timeout=2, @threaded=false, @soft_shutdown=false, @soft_shutdown_timeout=nil, @activate_agents=true, @connection_timeout=3, @default_batch_size=0, @default_batch_sleep_time=1>, @pluginname="shell", @plugintype=:agent, @requirements={}, @current_entity=nil>>

---- Ran command: cat /etc/motd ----
           Nodes: 1 / 1
     Pass / Fail: 0 / 1
      Start Time: 2023-09-22 08:33:53 -0500
  Discovery Time: 2100.06ms
      Agent Time: 503.14ms
      Total Time: 2603.21ms
smortex commented 1 year ago

Ruby 3.2 (shipped with Puppet 8) removed File#exists? in favor of File#exist?. It looks like this module has not been updated yet. Removing the s in each occurrence should fix the issue.

Would you like to submit a PR?

mdechiaro commented 1 year ago

Ok, I'll submit the PR, thanks

ripienaar commented 1 year ago

I released this to the forge if you want to give it a go https://forge.puppet.com/modules/choria/mcollective_agent_shell