Ask Your Question
0

Puppet Manifest to unzip a zipped file on a windows agent

asked 2015-10-05 07:44:03 -0500

michaelokoluko gravatar image

I keep getting the error 'Could not find command 'C:\puppetfolder\unzip.exe' or 'Could not find command 'C:\puppetfolder\ 7-Zip.exe' whichever one I try… basically I’m trying to unzip a zipped file (server.zip) into the directory C:\puppetfolder. Puppet is able to dowmload 7z1507.exe and unzip.exe in the C:\puppetfolder\ directory so the executales are their. But should I be using extract, unpack, unzip or 7zip in the command attribute to get this server.zip file to unzip into the same directory? Or is my argument wrong for this use case?

Below is my code. Any ideas?

-> file { 'C:\puppetfolder\7z1507.exe':

ensure   => 'present',
provider => 'windows',
mode     => '0775',
owner    => 'Administrator',
group    => 'Administrator',

}

-> file { 'C:\puppetfolder\unzip.exe':

ensure  => 'present',
mode    => '0775',
owner   => 'Administrator',
group   => 'Administrator',

}

->

file { 'C:\puppetfolder\server.zip':

ensure   => 'file',
source   => 'puppet:///modules/downloadscript/server.zip',
checksum => 'mtime',
mode     => '0775',
owner    => 'Administrator',
group    => 'Administrator',

}

-> exec {'unzip_c:\puppetfolder\server.zip':

 path         => 'c:\\puppetfolder\\unzip.exe',
command      => "C:\\puppetfolder\\unzip.exe /c C:\\puppetfolder\\server.zip C:\\puppetfolder -y",
provider     =>  'windows',

}

-> exec { 'install_c:\puppetfolder\downloadtest.ps1':

command     => 'C:\\puppetfolder\\downloadtest.bat',
logoutput   => 'true',
provider    => 'windows',

} }

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2015-10-05 09:59:20 -0500

pratyush04 gravatar image

It seems the resource ordering is reversed. downloadtest.ps1 should be at the beginning of the code.

exec { 'install_c:\puppetfolder\downloadtest.ps1':

command => 'C:\puppetfolder\downloadtest.bat', logoutput => 'true', provider => 'windows',

} -> .... ... -> .... -> exec {'unzip_c:\puppetfolder\server.zip':

path => 'c:\puppetfolder\unzip.exe', command => "C:\puppetfolder\unzip.exe /c C:\puppetfolder\server.zip C:\puppetfolder -y", provider => 'windows',

} }

edit flag offensive delete link more

Comments

Moreover, if you are using powershell 5.0, try using expand-archive. It would cut down 2 file resources, 7z.exe and unzip.exe.

pratyush04 gravatar imagepratyush04 ( 2015-10-05 10:03:13 -0500 )edit

Thanks for your response Pratyush04. I did - it was just redacted - have a code at the top that downloads dowloadtest.ps1 as my issue was with the unziping part - see next comment

michaelokoluko gravatar imagemichaelokoluko ( 2015-10-05 10:37:16 -0500 )edit

class downloadscript { file { 'C:\\puppetfolder\\downloadtest.ps1': ensure => 'present', source => 'puppet:///modules/downloadscript/downloadtest.ps1', mode => '0775', owner => 'Administrator', group => 'Administrator', } ->

michaelokoluko gravatar imagemichaelokoluko ( 2015-10-05 10:38:05 -0500 )edit

it now seems to run... but I'm getting a new error : "%1 is not a valid Win32 application. - CreateProcess is not a valid Win32 application". Not sure if it has to do with the fact that the machine is 64bits Win2k12

michaelokoluko gravatar imagemichaelokoluko ( 2015-10-05 10:39:54 -0500 )edit

Can you post the contents of downloadtest.bat?

pratyush04 gravatar imagepratyush04 ( 2015-10-05 11:42:57 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-10-05 07:44:03 -0500

Seen: 769 times

Last updated: Oct 05 '15