Adding the namevar special attribute

After we make use of the special attribute of the type, that is its namevar, we can then actually use a declaration of our resource using the Puppet DSL. The namevar should identify the resource uniquely within the underlying operating system, and must be something that can be prespecified, as shown in the following code:

Puppet::Type.newtype(:mynewtype) do

mynewparam(:name, :namevar => true) do
end

end

Now, we can declare our resource in the Puppet DSL. In this case, the namevar defaults to the resource title, as shown in the following code:

mynewtype { ‘foo': }

The resource title is used to make a reference to the resource uniquely inside the Puppet catalog. Hence, the namevar indicates the underlying system's name for that resource, as shown in the following code:

mynewtype { 'foo':
name => 'bar',
}

Then, run the following command:

$ puppet apply -e "mynewtype { 'foo': }"
notice: Finished catalog run in 0.09 seconds
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.6.77