choria-plugins / shell-agent Goto Github PK
View Code? Open in Web Editor NEWChoria Plugin for running arbitrary shell commands
License: Apache License 2.0
Choria Plugin for running arbitrary shell commands
License: Apache License 2.0
OS: Ubuntu 22.04
Puppet: 8.3.1
Version: mod 'choria-mcollective_agent_shell', '1.0.6'
Command: mco shell run 'echo foo' -W fqdn=puppetdev.domain.com
I tried setting the encoding as per the docs without success.
puppetdev:/etc/systemd/system$ cat /etc/systemd/system/choria-server.service.d/environment.conf
[Service]
Environment="LC_ALL=en"
I get a Cannot decode output from Shim for Ruby action shell#run: EOF
error on this system with simple commands. There are other Ubuntu 22.04 systems that do not have this issue, so it's strange that its occurring.
puppetdev.domain.com: ERROR: #<MCollective::RPC::Result:0x00007f3a2cd20628 @agent="shell", @action="run", @results={:sender=>"puppetdev.domain.com", :statuscode=>1, :statusmsg=>"Cannot decode output from Shim for Ruby action shell#run: EOF", :data=>{}}, @_ddl=#<MCollective::DDL::AgentDDL:0x00007f3a2c2aba08 @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.6", :url=>"https://github.com/choria-plugins/shell-agent", :timeout=>180}, @usage="", @config=#<MCollective::Config:0x00007f3a2c4f8fe0 @configured=true, @subscribe=[], @pluginconf={"nrpe.conf_dir"=>"/etc/nrpe.d", "choria.discovery_host"=>"puppetdb.domain.com", "choria.discovery_port"=>"8085", "choria.middleware_hosts"=>"choria.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"=>"puppetserver.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="client.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="debug", @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>>
I tried enabling debug logs and even tried efforts done on 1215 without any luck. Any assistance in exposing more verbose logs would be helpful.
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
Here's my hieradata:
choria::server: true
mcollective_choria::config:
security.serializer: "json"
mcollective::plugin_classes:
- mcollective_agent_bolt_tasks
- mcollective_agent_shell
Here's what an "mco shell" run does:
mgmt001 agent [tools.useast2] # mco shell
The Marionette Collective version 2.24.1
Unknown command 'shell', searched for applications in:
/opt/puppetlabs/mcollective/plugins
/opt/puppetlabs/puppet/lib/ruby/gems/2.5.0/gems/did_you_mean-1.2.0/lib
/opt/puppetlabs/puppet/lib/ruby/gems/2.5.0/gems/systemu-2.6.5/lib
/opt/puppetlabs/puppet/lib/ruby/gems/2.5.0/gems/nats-pure-0.6.2/lib
/opt/puppetlabs/puppet/lib/ruby/gems/2.5.0/gems/choria-mcorpc-support-2.24.2/lib
/opt/puppetlabs/puppet/lib/ruby/site_ruby/2.5.0
/opt/puppetlabs/puppet/lib/ruby/site_ruby/2.5.0/x86_64-linux
/opt/puppetlabs/puppet/lib/ruby/site_ruby
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/2.5.0
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/2.5.0/x86_64-linux
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby
/opt/puppetlabs/puppet/lib/ruby/2.5.0
/opt/puppetlabs/puppet/lib/ruby/2.5.0/x86_64-linux
Known commands:
choria completion facts
federation find help
inventory ping playbook
plugin r10k rpc
tasks
Type '/bin/mco help' for a detailed list of commands and '/bin/mco help command'
to get detailed help for a command
mgmt001 agent [tools.useast2] #
I don't know why it says this because:
mgmt001 plugins [tools.useast2] # find /opt/puppetlabs/mcollective/plugins/ -name "*shell*"
/opt/puppetlabs/mcollective/plugins/mcollective/agent/shell.ddl
/opt/puppetlabs/mcollective/plugins/mcollective/agent/shell.rb
/opt/puppetlabs/mcollective/plugins/mcollective/agent/shell
/opt/puppetlabs/mcollective/plugins/mcollective/agent/shell.json
mgmt001 plugins [tools.useast2] #
Am I missing something?
If I manually copy https://github.com/choria-plugins/shell-agent/blob/master/application/shell.rb to /opt/puppetlabs/mcollective/plugins/mcollective/application/, it just works. Is there some param I'm not setting?
The agent will return symbols for status which is not compatible with JSON based Choria
shell-agent/application/shell.rb
Line 261 in deb49d1
Not sure how to quantify this much more, as I don't have a super firm grasp on what's happening. The easiest way I know to see the issue is to try to "rm" (with no flags) a file that doesn't exist on a Centos 7 system. The issue does not occur on either Centos 6 or Centos 8. But on Centos 7 there is apparently some UTF-8 returned in the stderr message that causes Choria to return the error "Cannot decode output from Shim for Ruby action shell#run".
When this happens the command seems to run successfully, you just fail to get the proper response information back.
$ mco shell run ls
error 2018/03/06 02:10:33: pluginmanager.rb:171:in `rescue in loadclass' Failed to load MCollective::Application::Shell: cannot load such file -- mcollective/application/shell/watcher
Application 'shell' failed to load:
cannot load such file -- mcollective/application/shell/watcher (LoadError)
/opt/puppetlabs/puppet/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.