Ask Your Question
0

class to stage file and changing the ownership of the file

asked 2015-01-23 12:20:19 -0500

singaravelan gravatar image

updated 2015-01-23 16:18:31 -0500

GregLarkin gravatar image

Hi , I want to deploy a file and change the ownership of the file . here i am passing the variable values through Pe console.

Problem is , i am able to stage file but the ownership doesn't change. below is my code :

class deployapp::params($name=undef ,$path=undef,$source=undef, $target=undef) {
  include staging
  staging::file { "${name}":
    source => $source,
    target => "${path}/${name}",
  }

  class deployapp::params::war inherits deployapp::params {
    file {"${path}/${name}":
      owner => 'wicwso2',
      group => 'wicwso2',
    }
  }
}

any one help me , did use the inheritance class for the parameter is wrong ?

Ps: ran the debug mode, i am getting any errors , it passes the check but the ownership doesn't happen.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-01-23 16:26:35 -0500

GregLarkin gravatar image

updated 2015-01-27 22:37:09 -0500

First, make sure that when you define classes, you split them into separate .pp files that follow the Puppet module autoload naming convention. Next, I think you can rewrite your classes as a single class like so (some names changed to better reflect functionality):

class deployapp::stage_warfile(
  $name = undef,
  $path = undef, 
  $source = undef, 
  $target = undef) {

  include staging

  staging::file { $name:
    source => $source,
    target => "${path}/${name}",
  }

  file { "${path}/${name}":
    owner   => 'wicwso2',
    group   => 'wicwso2',
    require => Staging::File["${path}/${name}"],
  }
}

This is completely untested, so YMMV. The idea is that you stage the file into the target location first, then the file resource will be applied to change the owner and group. This class will live in a file named <moduledir>/modules/deployapp/manifests/stage_warfile.pp.

UPDATE: Here's a version of the code using a file resource default block to hopefully avoid the duplication definition error:

class deployapp::stage_warfile(
  $name = undef,
  $path = undef, 
  $source = undef, 
  $target = undef) {

  File {
    owner => 'wicwso2',
    group => 'wicwso2',
  }

  include staging

  staging::file { $name:
    source => $source,
    target => "${path}/${name}",
  }
}
edit flag offensive delete link more

Comments

Greg, i have tried this method alos , but it is causing duplicate variable declaration issue as i am using stage module and file resoure, Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate declaration: File[/wic/wso2as/repository/deployment/server/webapps/wws.war] is alre

singaravelan gravatar imagesingaravelan ( 2015-01-23 17:18:02 -0500 )edit

What is an example value of your $source parameter? You might also try changing the class to use a file resource default block, and I'll update my answer to show that.

GregLarkin gravatar imageGregLarkin ( 2015-01-27 22:35:22 -0500 )edit

Greg, i am able to avoid the duplication issue, but the issue is , staging doesnot have parameter called to replace the file or overwrite. because the application name war may be available in the dir , if that is the case stage module has replace the file or overwrite the new war. can you suggest me

singaravelan gravatar imagesingaravelan ( 2015-01-28 10:22:54 -0500 )edit

In order to replace the file, you'll have to manage and clean up the parent directory prior to staging the new version of the file. That is described here: http://bit.ly/1JK89hO The reason is that the internal file resource used by the module sets "replace => false".

GregLarkin gravatar imageGregLarkin ( 2015-01-28 20:21:39 -0500 )edit

Greg, i do not understand it properly . can you give the example sample code for the same scenario.

singaravelan gravatar imagesingaravelan ( 2015-01-28 22:01:45 -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-01-23 12:20:19 -0500

Seen: 332 times

Last updated: Jan 27 '15