F. Y.
2013-Jun-22 05:26 UTC
[Puppet Users] Can''t find $HOME when executing a command on Ubuntu
Hello Puppet Users, I am running into a weird issue when trying to execute an installer on Ubuntu 10.04/12.04 machines. I am using Puppet 3.2.1, and 3.2.2 respectively from Puppet Labs repo. This is the sample code: class installpackage { file { ''MyInstallerFile'': path => ''/tmp/MyInstallerFile'', ensure => present, owner => ''root'', group => ''root'', mode => ''777'', source => ''puppet:///extra_files/MyInstallerFile'', } file { ''answer_file'': path => ''/tmp/answer_file'', ensure => present, owner => ''root'', group => ''root'', mode => ''777'', source => ''puppet:///extra_file/answer_file'', } exec { "install": cwd => ''/tmp'', command => ''/tmp/MyInstallerFile --answer /tmp/answer_file'', logoutput => true, require => File[''MyInstallerFile'', ''answer_file''], } } The error I get is this (i.e. it can''t find $HOME set): Info: Retrieving plugin Info: Loading facts in /var/lib/puppet/lib/facter/root_home.rb Info: Loading facts in /var/lib/puppet/lib/facter/facter_dot_d.rb Info: Loading facts in /var/lib/puppet/lib/facter/pe_version.rb Info: Loading facts in /var/lib/puppet/lib/facter/puppet_vardir.rb Info: Caching catalog for puppetagent.example.com Info: Applying configuration version ''1370899438'' Notice: /Stage[main]/Installpackage/Exec[install]/returns: couldn''t find HOME environment variable to expand path Notice: /Stage[main]/Installpackage/Exec[install]/returns: while executing Notice: /Stage[main]/Installpackage/Exec[install]/returns: "file normalize ~" Notice: /Stage[main]/Installpackage/Exec[install]/returns: (procedure "::InstallJammer::HomeDir" line 2) Notice: /Stage[main]/Installpackage/Exec[install]/returns: invoked from within Notice: /Stage[main]/Installpackage/Exec[install]/returns: "::InstallJammer::HomeDir" Notice: /Stage[main]/Installpackage/Exec[install]/returns: (procedure "::InstallJammer::CommonInit" line 183) Notice: /Stage[main]/Installpackage/Exec[install]/returns: invoked from within Notice: /Stage[main]/Installpackage/Exec[install]/returns: "::InstallJammer::CommonInit" Notice: /Stage[main]/Installpackage/Exec[install]/returns: (procedure "::InstallJammer::InitInstall" line 19) Notice: /Stage[main]/Installpackage/Exec[install]/returns: invoked from within Notice: /Stage[main]/Installpackage/Exec[install]/returns: "::InstallJammer::InitInstall" Notice: /Stage[main]/Installpackage/Exec[install]/returns: (file "/installkitvfs/main.tcl" line 71313) Error: /tmp/MyInstallerFile --answer /tmp/answer_file returned 1 instead of one of [0] Error: /Stage[main]/Installpackage/Exec[install]/returns: change from notrun to 0 failed: MyInstallerFile --answer /tmp/answer_file returned 1 instead of one of [0] Notice: Finished catalog run in 5.31 seconds I did notice that if I append "sudo" before the command I want to execute, it works. Is there a more elegant solution? Please advise. F. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
jcbollinger
2013-Jun-24 13:05 UTC
[Puppet Users] Re: Can''t find $HOME when executing a command on Ubuntu
On Saturday, June 22, 2013 12:26:45 AM UTC-5, F. Y. wrote:> > Hello Puppet Users, > > I am running into a weird issue when trying to execute an installer on > Ubuntu 10.04/12.04 machines. I am using Puppet 3.2.1, and 3.2.2 > respectively from Puppet Labs repo. > > This is the sample code: > > class installpackage { > file { ''MyInstallerFile'': > path => ''/tmp/MyInstallerFile'', > ensure => present, > owner => ''root'', > group => ''root'', > mode => ''777'', > source => ''puppet:///extra_files/MyInstallerFile'', > } > file { ''answer_file'': > path => ''/tmp/answer_file'', > ensure => present, > owner => ''root'', > group => ''root'', > mode => ''777'', > source => ''puppet:///extra_file/answer_file'', > } > > exec { "install": > cwd => ''/tmp'', > command => ''/tmp/MyInstallerFile --answer /tmp/answer_file'', > logoutput => true, > require => File[''MyInstallerFile'', ''answer_file''], > } > } > > The error I get is this (i.e. it can''t find $HOME set): > > Info: Retrieving plugin > Info: Loading facts in /var/lib/puppet/lib/facter/root_home.rb > Info: Loading facts in /var/lib/puppet/lib/facter/facter_dot_d.rb > Info: Loading facts in /var/lib/puppet/lib/facter/pe_version.rb > Info: Loading facts in /var/lib/puppet/lib/facter/puppet_vardir.rb > Info: Caching catalog for puppetagent.example.com > Info: Applying configuration version ''1370899438'' > Notice: /Stage[main]/Installpackage/Exec[install]/returns: couldn''t find HOME environment variable to expand path > Notice: /Stage[main]/Installpackage/Exec[install]/returns: while executing > Notice: /Stage[main]/Installpackage/Exec[install]/returns: "file normalize ~" > Notice: /Stage[main]/Installpackage/Exec[install]/returns: (procedure "::InstallJammer::HomeDir" line 2) > Notice: /Stage[main]/Installpackage/Exec[install]/returns: invoked from within > Notice: /Stage[main]/Installpackage/Exec[install]/returns: "::InstallJammer::HomeDir" > Notice: /Stage[main]/Installpackage/Exec[install]/returns: (procedure "::InstallJammer::CommonInit" line 183) > Notice: /Stage[main]/Installpackage/Exec[install]/returns: invoked from within > Notice: /Stage[main]/Installpackage/Exec[install]/returns: "::InstallJammer::CommonInit" > Notice: /Stage[main]/Installpackage/Exec[install]/returns: (procedure "::InstallJammer::InitInstall" line 19) > Notice: /Stage[main]/Installpackage/Exec[install]/returns: invoked from within > Notice: /Stage[main]/Installpackage/Exec[install]/returns: "::InstallJammer::InitInstall" > Notice: /Stage[main]/Installpackage/Exec[install]/returns: (file "/installkitvfs/main.tcl" line 71313) > Error: /tmp/MyInstallerFile --answer /tmp/answer_file returned 1 instead of one of [0] > Error: /Stage[main]/Installpackage/Exec[install]/returns: change from notrun to 0 failed: MyInstallerFile --answer /tmp/answer_file returned 1 instead of one of [0] > Notice: Finished catalog run in 5.31 seconds > > I did notice that if I append "sudo" before the command I want to execute, it works. Is there a more elegant solution? > >By default, Puppet runs external commands in an extremely sparse environment. This is a good practice for both security, correctness, and consistency reasons. Ideally, you would not use Exec to run commands that depend on their environment, but in practice, you cannot always avoid that. Running a command indirectly via sudo works around your issue because sudo by default provides an environment that is slightly richer than the one Puppet provides. A better solution, however, is to use the Exec''s ''env'' parameter to set environment variables that your script needs. Be aware also of the ''path'' and ''cwd'' parameters, which have related purposes. You should also consider, however, why your script needs $HOME in the first place. It shouldn''t need that for temp files, and you probably don''t want to install the software in the Puppet agent''s (or root''s) home directory, or to modify anything there or even base any decisions on the files it may or may not find there. So what does the script want it for, that you actually want it to do? John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.