user2478159
user2478159

Reputation: 133

issue while ordering puppet class execution

I have this recursive copy action called through

class first_class{
    file{'some name':
                    ensure => 'directory',
                    path => '/path/to/here',
                    owner  => 'some_owner',
                    group  => 'some_group',
                    recurse => remote,
                    source => 'puppet:///modules/scripts'
            }
}
class second_class{
file{'tmp':
                ensure => 'present',
                path => '/path/to/here/tmp.sh',
                owner => 'some_owner',
                group => 'some_group',
                mode => '0755',
                notify => Exec['some_process']
                }
}

The files are recursively copied but the content is not. So it seems that the file is recreated by the second_class, however in my main manifest file I have

node default {

Class { 'my_module::first_class':} -> Class { 'my_module::second_class':}

Is there a way to tackle it ?

Upvotes: 0

Views: 30

Answers (1)

John Bollinger
John Bollinger

Reputation: 180103

The files are recursively copied but the content is not. So it seems that the file is recreated by the second_class

Actually, no, that's not quite what is happening. Your second_class contains an explicit declaration of File['tmp']. Each resource can be declared only once, and explicit File declarations take precedence over implicit ones generated for the contents of recursively-managed directories. This is a feature. Thus, the file in question is not being recreated by the explicit declaration; rather, it is being managed only according to that declaration.

Because File['tmp'] uses ensure => present, it accepts any form of file (directory, symlink, regular file, etc.), and if there is no such file at all then it will create an empty ordinary file. That's what you observe. It has nothing to do with order of resource application.

Is there a way to tackle it ?

Yes. If you want the file to be managed via File['some name'] then do not declare an explicit resource for it. If you must declare it explicitly, e.g. so as to set its notify property, then make that declaration reflect the complete desired target-machine state.

Overall, I suspect you might benefit from some refactoring, as the situation has some code smell. Be aware also that recursive file management has always been ... quirky ... at best. It has its uses, but often you are better off with something else.

Upvotes: 1

Related Questions