File Management using puppet

16 views
Skip to first unread message

ggun

unread,
May 24, 2017, 10:16:11 AM5/24/17
to Puppet Developers, Gaurav Gundal
Hi Experts,

I need your help in below requirement.
Requirement
I need to create a file (xxx_logrotate.conf) with content as below 

                        /xx/xx/xx.log {

                                                             weekly

                                                             copytruncate

                                                             rotate 8

                                                             compress

                                                            maxage 180

                                                            missingok

                                                            }


2. Create the symlink for above create file xxx_logrotate.conf to /etc/logrotate.d/xxx_logrotate.conf


My approach


1. I went ahead creating the file with using erb tempalte for adding the file content but when I create a new resource to create the symlik for the source and target. The puppet run fails with duplicate file resource 


  file { 'xxx-log-rotation-config-file':

    ensure                  => 'present',

    path                    => '/xxx/conf/xxx_logrotate.conf',

    content                 => template('aaa/xxx_logrotate.conf.erb'),

    owner                   => 'root',

    group                   => 'root',    

  }


  file { '/xxx/conf/xxx_logrotate.conf':

    ensure                  => 'link',

    target                  => '/etc/logrotate.d/xxx_logrotate.conf',

    require                 => File['xxx-log-rotation-config-file'],    

  }


The puppet run fails for above code with below error 

Error: Evaluation Error: Error while evaluating a Resource Statement, Duplicate declaration: File[/xxx/conf/mysql_logrotate.conf] is already declared in file /etc/puppetlabs/code/environments/production/modules/xxx/manifests/postinstall.pp:46; cannot redeclare at /etc/puppetlabs/code/environments/production/modules/xxx/manifests/postinstall.pp:54 at /etc/puppetlabs/code/environments/production/modules/xxx/manifests/postinstall.pp:54:3 



Is there a better way of handling this without any issue using file resource?

David Schmitt

unread,
May 24, 2017, 10:44:33 AM5/24/17
to puppe...@googlegroups.com, Gaurav Gundal
You need to decide where you want the file, and where you want the symlink. As it stands, you define the file /xxx/conf/xxx_logrotate.conf twice, once with the templated content, once as symlink. In your situation, I'd switch the title and target of the symlink around.


Cheers, David

ggun

unread,
May 24, 2017, 11:26:08 AM5/24/17
to Puppet Developers, gaurav...@glic.com
Thank you. David for immediate reply. Answer - ' I'd switch the title and target of the symlink around'
Reply all
Reply to author
Forward
0 new messages