Gael
2012-Mar-28 18:01 UTC
[Puppet Users] Strange behaviour of the exec / command function
Hi all, I am currently creating a java class to automate its installation. You can find the class definition is below. In a nutshell, it is creating a temp folder to put the ".bin" file, copy the .bin file in the folder then runs the installation. Since running the bin will create a couple of ".rpm" files, I wanted them to be in the temp folder and not in "/". The line that caused me problems is: command => "sh -c ''cd ${$path_java_tmp_folder} && pwd && yes | ./$ {bin_java_install_package} ''", Originally, I tried command => "sh -c ''cd ${$path_java_tmp_folder} && yes | ./$ {bin_java_install_package} ''", And at runtime, I received the following error message "err: / Stage[main]/Java/Exec[install-java]/returns: change from notrun to 0 failed: sh: ./jdk-6u31-linux-x64-rpm.bin: No such file or directory" Then I added: "&& pwd " and now it works... Whereas the "&& pwd" does not actually do anything ... Does anyone know about this? Would it be a bug? Thanks in advance for your help. Gael class java { $path_java_tmp_folder = ''/opt/java/'' $bin_java_install_package = ''jdk-6u31-linux-x64-rpm.bin'' $path_java_tmp_install_package = "${path_java_tmp_folder}$ {bin_java_install_package}" # 1 - create the folder # 2 - copy the jdk file in the folder # 3 - install the jdk rpm File[''java-tmp-folder'']->File[''copy-java-install'']->Exec[''install-java'']file { # Create the folder to store the bin file ''java-tmp-folder'': ensure => directory, path => $path_java_tmp_folder, owner => ''root'', group => ''root'', recurse => true ; # copy the jdk across ''copy-java-install'': ensure => file , path => $path_java_tmp_install_package, source => "puppet:///modules/java/$ {bin_java_install_package}", owner => ''root'' , group => ''root'' , mode => ''0744'' , } exec { "install-java": path => ["/usr/bin","/bin"], command => "sh -c ''cd ${$path_java_tmp_folder} && pwd && yes | ./${bin_java_install_package} ''", unless => "test -e /usr/bin/java"; } } -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
jcbollinger
2012-Mar-29 13:03 UTC
[Puppet Users] Re: Strange behaviour of the exec / command function
On Mar 28, 1:01 pm, Gael <gael.reign...@gmail.com> wrote:> Hi all, > > I am currently creating a java class to automate its installation. You > can find the class definition is below. > > In a nutshell, it is creating a temp folder to put the ".bin" file, > copy the .bin file in the folder then runs the installation. > > Since running the bin will create a couple of ".rpm" files, I wanted > them to be in the temp folder and not in "/".It would be easier and better to run the .bin file once, manually, then take the resulting RPMs and put them in a local Yum repository. If you don''t already have a local Yum repository then you should create one, and not just for the Java rpms. It''s not hard.> The line that caused me problems is: > command => "sh -c ''cd ${$path_java_tmp_folder} && pwd && yes | ./$ > {bin_java_install_package} ''", > > Originally, I tried > command => "sh -c ''cd ${$path_java_tmp_folder} && yes | ./$ > {bin_java_install_package} ''", > > And at runtime, I received the following error message "err: / > Stage[main]/Java/Exec[install-java]/returns: change from notrun to 0 > failed: sh: ./jdk-6u31-linux-x64-rpm.bin: No such file or directory" > > Then I added: "&& pwd " and now it works... Whereas the "&& pwd" does > not actually do anything ... > > Does anyone know about this? Would it be a bug?The "${$path_java_tmp_folder}" construction looks very suspicious to me. I suspect that you''re not ending up in the directory you think you''re ending up in. I cannot imagine why inserting "&& pwd" into the command would fix it, so I suspect that that probably was not the only change.> class java { > > $path_java_tmp_folder = ''/opt/java/'' > $bin_java_install_package = ''jdk-6u31-linux-x64-rpm.bin'' > $path_java_tmp_install_package = "${path_java_tmp_folder}$ > {bin_java_install_package}" > > # 1 - create the folder > # 2 - copy the jdk file in the folder > # 3 - install the jdk rpm > > File[''java-tmp-folder'']->File[''copy-java-install'']- > > >Exec[''install-java''] > > file { > # Create the folder to store the bin file > ''java-tmp-folder'': > > ensure => directory, > path => $path_java_tmp_folder, > owner => ''root'', > group => ''root'', > recurse => true ; > > # copy the jdk across > > ''copy-java-install'': > > ensure => file , > path => $path_java_tmp_install_package, > source => "puppet:///modules/java/$ > {bin_java_install_package}", > owner => ''root'' , > group => ''root'' , > mode => ''0744'' , > > } > > exec { "install-java": > > path => ["/usr/bin","/bin"], > command => "sh -c ''cd ${$path_java_tmp_folder} && pwd > && yes | ./${bin_java_install_package} ''", > unless => "test -e /usr/bin/java"; > > } > > > > }Note that this class forces you to keep the temp directory and installer file on every node -- if you remove them then Puppet will copy them down again. If you keep them, on the other hand, then Puppet has to checksum the local and remote copies on every run. Really, put the RPMs in a local repo and just use Yum (via Puppet) to install them and keep them up to date. Or if you are using a distro that provides Java packages (many do) then consider using the distribution''s Java packages (I''m talking mainly about openjdk, not gcc-java). John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.