Ask Your Question
0

Tar file is not extracted to the directory

asked 2017-11-06 08:34:51 -0600

I am using the following manifest to untar a file. I tried the below code to untar the file.

file { '/home/testuser/apache-tomcat-7.0.82.tar.gz':
  source => '/home/testuser/apache-tomcat-7.0.82.tar.gz'
  notify => Exec['untar'],
}

file { '/home/testuser/puppetMod1/':
  ensure => 'directory',
  mode   => '1777',
  owner  => 'testuser',
  group  => 'testuser',
}

exec { 'untar':
  command     => 'tar -xvf /home/testuser/apache-tomcat-7.0.82.tar.gz -C /home/testuser/puppetMod1',
  cwd         => '/home/testuser/',
  user        => 'testuser',
  require     => File["/home/testuser/puppetMod1/"],
  refreshonly => true,

It creates the directory, unfortunately does not extract the .tar.gz file to the directory puppetMod1. So i tried a simple manifest as below to extract the .tar file. Even this one does not create the extract the .tar file.

exec { 'untar':
  command     => '/bin/tar -xzf /home/testuser/apache-tomcat-7.0.82.tar.gz -C /home/testuser/puppetMod2',
  creates    => '/home/testuser/puppetMod2',
  user        => 'testuser',
 # refreshonly => true,
}

For both the manifest, what am i missing. Can you through some lights what I can add to this code?

edit retag flag offensive close merge delete

Comments

You are probably looking for the functionality in https://forge.puppet.com/puppet/archive, but there are similar patterns in an exec based flow in the staging module - https://forge.puppet.com/puppet/staging . If you want specific feedback on why it's not working, I can look deeper...

DarylW gravatar imageDarylW ( 2017-11-06 14:14:39 -0600 )edit

Yes DaryW. I need to understand why this is not working.As I am learning the Puppet Manifest, it would be give be better insight.

ZosBHAI gravatar imageZosBHAI ( 2017-11-06 21:44:56 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2017-11-08 03:17:52 -0600

stivesso gravatar image

Hi ZosBHAI,

I can see some error in the code you shared that may explained why it wasn't working,

Let me start with your second example, In that example, you set creates => '/home/testuser/puppetMod2' on the exec resource, meaning that the exec will only run if /home/testuser/puppetMod2 doesn't exist (And seeing the tar command, seems like /home/testuser/puppetMod2 already exists, meaning that the exec command won't be executed).
For example, the following code will work, but the exec will keep running every time Puppet runs (re-extract the file at every run).

file { '/home/testuser/puppet-enterprise':
  ensure => 'directory',
  mode   => '1777',
  owner  => 'testuser',
  group  => 'testuser',
}

exec { 'untar':
  command     => '/bin/tar -xvf /home/testuser/puppet-enterprise-2016.4.0-el-7-x86_64.tar.gz -C /home/testuser/puppet-enterprise',
  user        => 'testuser',
  require     => File["/home/testuser/puppet-enterprise"]
}

To avoid the re-extraction, we can set the creates attribute to one of the extracted file (More details over that attribute here). See the example below:

file { '/home/testuser/puppet-enterprise':
  ensure => 'directory',
  mode   => '1777',
  owner  => 'testuser',
  group  => 'testuser',
}

exec { 'untar':
  command     => '/bin/tar -xvf /home/testuser/puppet-enterprise-2016.4.0-el-7-x86_64.tar.gz -C /home/testuser/puppet-enterprise',
  user        => 'testuser',
  creates     => '/home/testuser/puppet-enterprise/puppet-enterprise-2016.4.0-el-7-x86_64/LICENSE.txt',
  require     => File["/home/testuser/puppet-enterprise"]
}

In the first example, the source and destination of the file resource seems to be the same (/home/testuser/apache-tomcat-7.0.82.tar.gz)! If you are trying to copy files from the Puppet Master to your local Server, then you should instead use puppet: URI, (check the doc). Note also that If the file /home/testuser/apache-tomcat-7.0.82.tar.gz already exists, nothing will happen (as refreshonly is set on exec, it will be executed only after the first successful creation/copy of the file /home/testuser/apache-tomcat-7.0.82.tar.gz from the source...).

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2017-11-06 08:34:51 -0600

Seen: 21 times

Last updated: Nov 08