DIMV
DIMV

Reputation: 15

Using complex exported resource tags in Puppet 7 - is it possible

I need to define a Puppet class and exported resources similarly to https://serverfault.com/questions/559019/how-to-collect-tagged-exported-resources with the small variance that I need to add class app_primary($datacenter_$zone_$tenant_$role) for the satellites servers to join the primary and then use the same class identifier as a tag like tag => "$datacenter_$zone_$tenant_$role", Can you please advise if using such complex tags is possible or I should stick to the KISS principle. Thanks.

Reading from the documentation I should aim for the most unique exported resource tag type possible or work with hiera ( out of my bounds and privileges for the time being ). Therefore decided to ask before digging down further in this

Upvotes: 0

Views: 107

Answers (1)

John Bollinger
John Bollinger

Reputation: 180093

I need to add class app_primary($datacenter_$zone_$tenant_$role) for the satellites servers

That doesn't make sense. The appearance of the class keyword suggests that that is the beginning of a class definition for class app_primary. The parentheses would then contain a list of class parameters -- names, optionally types, and optionally initial values. $datacenter_$zone_$tenant_$role is not a valid parameter name. Possibly you want this class to have four distinct parameters here:

class app_primary($datacenter, $zone, $tenant, $role) {
  # ...
}

to join the primary and then use the same class identifier as a tag like tag => "$datacenter_$zone_$tenant_$role",

Class parameters do not identify a class. The identifier of the class above is app_primary.

However, you can form a string that concatenates the values of the parameters, and tag resources with it. The form of the string would be something like this: "${datacenter}_${zone}_${tenant}_${role}". That tagging would distinguish resources declared by this class with one set of parameter values from resources declared by this class (for a different node) with a different set of parameter values.

Can you please advise if using such complex tags is possible

Certainly it's possible. And I'm not sure I would characterize the result as "complex".

or I should stick to the KISS principle.

Simplicity is relative. If you have a simpler alternative in mind then KISS might be something to consider, but until then, it's irrelevant.

Upvotes: 1

Related Questions