Ask Your Question
0

Copy and uncompress a gzipped file

asked 2014-01-15 05:18:53 -0600

pwaring gravatar image

updated 2014-01-15 05:19:18 -0600

I have a compressed .gz file which I'm copying from my local machine to a VM (controlled with Vagrant) using the following code in my Puppet manifest:

file { '/home/vagrant/file.sql.gz':
  ensure => present,
  mode => 0600,
  source => '/vagrant_data/file.sql.gz',
}

I want to uncompress the file after it has been copied - i.e. the equivalent of running gunzip file.sql.gz, but I can't find a way to do this in Puppet, either as part of the default install or as a module.

I could uncompress the file at the destination and copy that, but having ... (more)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-01-15 06:16:05 -0600

frederik gravatar image

Try something among this lines:

file { '/home/vagrant/file.sql.gz':  
  ensure => present,
  mode => 0600,
  source => '/vagrant_data/file.sql.gz',
  before => Exec['unpack_file_sql.gz'],
}

exec {'unpack_file_sql.gz':
  unless => 'test -f /home/vagrant/file.sql',
  cwd => '/home/vagrant',
  command => 'gunzip file.sql.gz',
}

Untested, but should work.

Frederik

edit flag offensive delete link more

Comments

Thanks, that worked once I specified the full path to the `test` and `gunzip` binaries. I'm surprised there's no built-in/module support for this though, as I'd ...(more)

pwaring gravatar imagepwaring ( 2014-01-15 07:46:56 -0600 )edit

Instead of hardcoding the full path you can modify the exec resource, adding: [...] path => '/sbin:/usr/sbin:/bin:/usr/bin', [...] this should be more portable. You can also set this ...(more)

frederik gravatar imagefrederik ( 2014-01-15 10:28:49 -0600 )edit

Thanks, that's a useful tip - although again I'm a bit surprised that Puppet doesn't set the path automatically as it knows what OS/distribution I'm running.

pwaring gravatar imagepwaring ( 2014-01-16 03:52:43 -0600 )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: 2014-01-15 05:18:53 -0600

Seen: 5,859 times

Last updated: Jan 15 '14