Wednesday, January 21, 2015

Daily Puppet 3 - Inheritance

With the inheritance we can set the order in which resources are applied on an agent.

A test manifest is shown below, it is rather simple one.


#Demonstrate the inheritance
class ownerfile {
file { "/tmp/owner.txt":
content => " I am the owner and the next file is depeandent on me",
before => File["/tmp/depenfile"]
}
file { "/tmp/depenfile":
content => " I am the Dependent of owner"
}
}
view raw gistfile1.rb hosted with ❤ by GitHub



Here we have defined a class “ownerfile”, which has a resource file “/tmp/owner.txt”. There is another file “/tmp/depenfile”, which will be created after the owners.txt file.


First owner.txt file is created and then depenfile is created.


Another approach is using the “require”

class ownerfile {
file { "/tmp/dependrequire.txt":
content => " My requirement is owner txt file\n ",
require => File["/tmp/owner.txt"]
}
file { "/tmp/owner.txt":
content => " I am the of owner\n"
}
}
view raw Demo1 hosted with ❤ by GitHub


In the above manifest it is shown that,
File resource “/tmp/dependrequire.txt”  defined which requires another resource which is a file resource too, “tmp/owners.txt”
First owners.txt is created as it is required by the file resource dependrequire.txt. Then dependrequire.txt is created.

No comments:

Post a Comment