About | FAQ | Help
Ask Your Question
0

how to declare same resource in puppet in different modules

asked 2017-12-11 08:17:46 -0500

phanikumar gravatar image

updated 2017-12-11 08:20:22 -0500

Hello team,

I had a situation where I have two modules. I would like to install wget package using both modules as it is mandatory for each to work perfectly. But when I am assigning these two modules to the agent I am getting a conflict with wget package resource assignment. I can't delete wget package resource declaration in any of the modules as assigning it individual won't work if I delete them. Any help is really appreciated.

Thank you.

edit retag flag offensive close merge delete

Comments

Can't you use `curl(1)`? Because `curl(1)` is already a dependency of Puppet itself, so it's _definitely_ there. Depending on your installation method it's either the regular `curl` package (so at `/usr/bin/curl`) or at `/opt/puppetlabs/puppet/bin/curl`.

Kai Burghardt gravatar imageKai Burghardt ( 2017-12-11 12:24:28 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted
1

answered 2017-12-14 10:14:54 -0500

zsl gravatar image

updated 2017-12-14 22:30:06 -0500

Simply use ensure_packages statement frompuppetlabs-stdlibs module. It takes a list of packages in an array or hash and installs them only if they don't already exist.

in your case for example:

  1. module foo

    class foo {
         ensure_packages(['wget'], { ensure => 'latest' })
    }
    
  2. module bar

    class bar {
         ensure_packages(['wget'], { ensure => 'latest' })
    }
    
  3. now you can include both of them without duplicate error.

    include foo
    include bar
    

Update:

For the duplicate file resource problem you described, there is no need to delete the directory first, you can just use force parameter.

file { 'tomcat_link':
  path   =>  "${tomcat_base_path}/tomcat2",
  ensure =>  "link",
  target =>  "${tomcat_base_path}/${tomcat8}",
  force  =>  true,
}
edit flag offensive delete link more
0

answered 2017-12-11 13:46:50 -0500

phanikumar gravatar image

updated 2017-12-14 11:25:25 -0500

DarylW gravatar image

now. I have a similar issue with file resource. where I need to create a symbolic link after deleting a directory with symbolic link name. But it is throwing me error if I am specifying the same path in file resource and specifying ensure absent for one and ensure link for other.

file{'rename_tomcat2_move':
            ensure  =>      'absent',
            recurse =>      true,
            purge   =>      true,
            force   =>      true,
            path    =>      "${tomcat_base_path}/tomcat2",
        }
file{'tomcat_link':
        path            =>      "${tomcat_base_path}/tomcat2",
        ensure          =>      'link',
        target          =>      "${tomcat_base_path}/${tomcat8}",
    }

The above code is giving me 500 error stating that the resource is already declared.

edit flag offensive delete link more

Comments

You can't manage the same resource multiple times... there is no reason to say 'absent' and then 'it should be a link'... you just describe the end state 'it should be a link' and then it will be a link.

DarylW gravatar imageDarylW ( 2017-12-14 11:26:24 -0500 )edit

I have a folder with the name tomcat which should be deleted first so I declared the resource as absent. If we have a folder them puppet can't create a link with that name.

phanikumar gravatar imagephanikumar ( 2017-12-14 11:59:10 -0500 )edit
1

@phanikumar You can use `force` parameter. Refer to my updated answer.

zsl gravatar imagezsl ( 2017-12-14 22:31:59 -0500 )edit
0

answered 2017-12-11 08:39:08 -0500

you can create a third module - called say wget module which installes the package.

you can then include the wget package in each of your new modules...

edit flag offensive delete link more

Comments

It will satisfy my requirement. But if I have several other modules like this it is not going to be a good practice I believe. Even if I have some other requirement like dynamically changing the versions for each package creating a separate wget module would be a blocker for me I believe.

phanikumar gravatar imagephanikumar ( 2017-12-11 10:07:49 -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: 2017-12-11 08:17:46 -0500

Seen: 212 times

Last updated: Dec 14 '17