|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +built_from_commit: c0f933882f92b7998fe94e2a57bbdf69f77ac61e |
| 4 | +title: Metaparameter Reference |
| 5 | +toc: columns |
| 6 | +canonical: "/puppet/latest/metaparameter.html" |
| 7 | +--- |
| 8 | + |
| 9 | +# Metaparameter Reference |
| 10 | + |
| 11 | +> **NOTE:** This page was generated from the Puppet source code on 2024-08-29 09:52:11 -0700 |
| 12 | +
|
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +Metaparameters are attributes that work with any resource type, including custom |
| 18 | +types and defined types. |
| 19 | + |
| 20 | +In general, they affect _Puppet's_ behavior rather than the desired state of the |
| 21 | +resource. Metaparameters do things like add metadata to a resource (`alias`, |
| 22 | +`tag`), set limits on when the resource should be synced (`require`, `schedule`, |
| 23 | +etc.), prevent Puppet from making changes (`noop`), and change logging verbosity |
| 24 | +(`loglevel`). |
| 25 | + |
| 26 | +## Available Metaparameters |
| 27 | + |
| 28 | + ### alias |
| 29 | + |
| 30 | +Creates an alias for the resource. Puppet uses this internally when you |
| 31 | +provide a symbolic title and an explicit namevar value: |
| 32 | + |
| 33 | + file { 'sshdconfig': |
| 34 | + path => $os['name'] ? { |
| 35 | + solaris => '/usr/local/etc/ssh/sshd_config', |
| 36 | + default => '/etc/ssh/sshd_config', |
| 37 | + }, |
| 38 | + source => '...' |
| 39 | + } |
| 40 | + |
| 41 | + service { 'sshd': |
| 42 | + subscribe => File['sshdconfig'], |
| 43 | + } |
| 44 | + |
| 45 | +When you use this feature, the parser sets `sshdconfig` as the title, |
| 46 | +and the library sets that as an alias for the file so the dependency |
| 47 | +lookup in `Service['sshd']` works. You can use this metaparameter yourself, |
| 48 | +but note that aliases generally only work for creating relationships; anything |
| 49 | +else that refers to an existing resource (such as amending or overriding |
| 50 | +resource attributes in an inherited class) must use the resource's exact |
| 51 | +title. For example, the following code will not work: |
| 52 | + |
| 53 | + file { '/etc/ssh/sshd_config': |
| 54 | + owner => root, |
| 55 | + group => root, |
| 56 | + alias => 'sshdconfig', |
| 57 | + } |
| 58 | + |
| 59 | + File['sshdconfig'] { |
| 60 | + mode => '0644', |
| 61 | + } |
| 62 | + |
| 63 | +There's no way here for the Puppet parser to know that these two stanzas |
| 64 | +should be affecting the same file. |
| 65 | + |
| 66 | +### audit |
| 67 | + |
| 68 | +Marks a subset of this resource's unmanaged attributes for auditing. Accepts an |
| 69 | +attribute name, an array of attribute names, or `all`. |
| 70 | + |
| 71 | +Auditing a resource attribute has two effects: First, whenever a catalog |
| 72 | +is applied with puppet apply or puppet agent, Puppet will check whether |
| 73 | +that attribute of the resource has been modified, comparing its current |
| 74 | +value to the previous run; any change will be logged alongside any actions |
| 75 | +performed by Puppet while applying the catalog. |
| 76 | + |
| 77 | +Secondly, marking a resource attribute for auditing will include that |
| 78 | +attribute in inspection reports generated by puppet inspect; see the |
| 79 | +puppet inspect documentation for more details. |
| 80 | + |
| 81 | +Managed attributes for a resource can also be audited, but note that |
| 82 | +changes made by Puppet will be logged as additional modifications. (I.e. |
| 83 | +if a user manually edits a file whose contents are audited and managed, |
| 84 | +puppet agent's next two runs will both log an audit notice: the first run |
| 85 | +will log the user's edit and then revert the file to the desired state, |
| 86 | +and the second run will log the edit made by Puppet.) |
| 87 | + |
| 88 | +### before |
| 89 | + |
| 90 | +One or more resources that depend on this resource, expressed as |
| 91 | +[resource references](https://puppet.com/docs/puppet/latest/lang_data_resource_reference.html). |
| 92 | +Multiple resources can be specified as an array of references. When this |
| 93 | +attribute is present: |
| 94 | + |
| 95 | +* This resource will be applied _before_ the dependent resources. |
| 96 | + |
| 97 | +This is one of the four relationship metaparameters, along with |
| 98 | +`require`, `notify`, and `subscribe`. For more context, including the |
| 99 | +alternate chaining arrow (`->` and `~>`) syntax, see |
| 100 | +[the language page on relationships](https://puppet.com/docs/puppet/latest/lang_relationships.html). |
| 101 | + |
| 102 | +### loglevel |
| 103 | + |
| 104 | +Sets the level that information will be logged. |
| 105 | +The log levels have the biggest impact when logs are sent to |
| 106 | +syslog (which is currently the default). |
| 107 | + |
| 108 | +The order of the log levels, in decreasing priority, is: |
| 109 | + |
| 110 | +* `emerg` |
| 111 | +* `alert` |
| 112 | +* `crit` |
| 113 | +* `err` |
| 114 | +* `warning` |
| 115 | +* `notice` |
| 116 | +* `info` / `verbose` |
| 117 | +* `debug` |
| 118 | + |
| 119 | +Valid values are `debug`, `info`, `notice`, `warning`, `err`, `alert`, `emerg`, `crit`, `verbose`. |
| 120 | + |
| 121 | +### noop |
| 122 | + |
| 123 | +Whether to apply this resource in noop mode. |
| 124 | + |
| 125 | +When applying a resource in noop mode, Puppet will check whether it is in sync, |
| 126 | +like it does when running normally. However, if a resource attribute is not in |
| 127 | +the desired state (as declared in the catalog), Puppet will take no |
| 128 | +action, and will instead report the changes it _would_ have made. These |
| 129 | +simulated changes will appear in the report sent to the primary Puppet server, or |
| 130 | +be shown on the console if running puppet agent or puppet apply in the |
| 131 | +foreground. The simulated changes will not send refresh events to any |
| 132 | +subscribing or notified resources, although Puppet will log that a refresh |
| 133 | +event _would_ have been sent. |
| 134 | + |
| 135 | +**Important note:** |
| 136 | +[The `noop` setting](https://puppet.com/docs/puppet/latest/configuration.html#noop) |
| 137 | +allows you to globally enable or disable noop mode, but it will _not_ override |
| 138 | +the `noop` metaparameter on individual resources. That is, the value of the |
| 139 | +global `noop` setting will _only_ affect resources that do not have an explicit |
| 140 | +value set for their `noop` attribute. |
| 141 | + |
| 142 | +Valid values are `true`, `false`. |
| 143 | + |
| 144 | +### notify |
| 145 | + |
| 146 | +One or more resources that depend on this resource, expressed as |
| 147 | +[resource references](https://puppet.com/docs/puppet/latest/lang_data_resource_reference.html). |
| 148 | +Multiple resources can be specified as an array of references. When this |
| 149 | +attribute is present: |
| 150 | + |
| 151 | +* This resource will be applied _before_ the notified resources. |
| 152 | +* If Puppet makes changes to this resource, it will cause all of the |
| 153 | + notified resources to _refresh._ (Refresh behavior varies by resource |
| 154 | + type: services will restart, mounts will unmount and re-mount, etc. Not |
| 155 | + all types can refresh.) |
| 156 | + |
| 157 | +This is one of the four relationship metaparameters, along with |
| 158 | +`before`, `require`, and `subscribe`. For more context, including the |
| 159 | +alternate chaining arrow (`->` and `~>`) syntax, see |
| 160 | +[the language page on relationships](https://puppet.com/docs/puppet/latest/lang_relationships.html). |
| 161 | + |
| 162 | +### require |
| 163 | + |
| 164 | +One or more resources that this resource depends on, expressed as |
| 165 | +[resource references](https://puppet.com/docs/puppet/latest/lang_data_resource_reference.html). |
| 166 | +Multiple resources can be specified as an array of references. When this |
| 167 | +attribute is present: |
| 168 | + |
| 169 | +* The required resources will be applied **before** this resource. |
| 170 | + |
| 171 | +This is one of the four relationship metaparameters, along with |
| 172 | +`before`, `notify`, and `subscribe`. For more context, including the |
| 173 | +alternate chaining arrow (`->` and `~>`) syntax, see |
| 174 | +[the language page on relationships](https://puppet.com/docs/puppet/latest/lang_relationships.html). |
| 175 | + |
| 176 | +### schedule |
| 177 | + |
| 178 | +A schedule to govern when Puppet is allowed to manage this resource. |
| 179 | +The value of this metaparameter must be the `name` of a `schedule` |
| 180 | +resource. This means you must declare a schedule resource, then |
| 181 | +refer to it by name; see |
| 182 | +[the docs for the `schedule` type](https://puppet.com/docs/puppet/latest/type.html#schedule) |
| 183 | +for more info. |
| 184 | + |
| 185 | + schedule { 'everyday': |
| 186 | + period => daily, |
| 187 | + range => "2-4" |
| 188 | + } |
| 189 | + |
| 190 | + exec { "/usr/bin/apt-get update": |
| 191 | + schedule => 'everyday' |
| 192 | + } |
| 193 | + |
| 194 | +Note that you can declare the schedule resource anywhere in your |
| 195 | +manifests, as long as it ends up in the final compiled catalog. |
| 196 | + |
| 197 | +### stage |
| 198 | + |
| 199 | +Which run stage this class should reside in. |
| 200 | + |
| 201 | +**Note: This metaparameter can only be used on classes,** and only when |
| 202 | +declaring them with the resource-like syntax. It cannot be used on normal |
| 203 | +resources or on classes declared with `include`. |
| 204 | + |
| 205 | +By default, all classes are declared in the `main` stage. To assign a class |
| 206 | +to a different stage, you must: |
| 207 | + |
| 208 | +* Declare the new stage as a [`stage` resource](https://puppet.com/docs/puppet/latest/type.html#stage). |
| 209 | +* Declare an order relationship between the new stage and the `main` stage. |
| 210 | +* Use the resource-like syntax to declare the class, and set the `stage` |
| 211 | + metaparameter to the name of the desired stage. |
| 212 | + |
| 213 | +For example: |
| 214 | + |
| 215 | + stage { 'pre': |
| 216 | + before => Stage['main'], |
| 217 | + } |
| 218 | + |
| 219 | + class { 'apt-updates': |
| 220 | + stage => 'pre', |
| 221 | + } |
| 222 | + |
| 223 | +### subscribe |
| 224 | + |
| 225 | +One or more resources that this resource depends on, expressed as |
| 226 | +[resource references](https://puppet.com/docs/puppet/latest/lang_data_resource_reference.html). |
| 227 | +Multiple resources can be specified as an array of references. When this |
| 228 | +attribute is present: |
| 229 | + |
| 230 | +* The subscribed resources will be applied _before_ this resource. |
| 231 | +* If Puppet makes changes to any of the subscribed resources, it will cause |
| 232 | + this resource to _refresh._ (Refresh behavior varies by resource |
| 233 | + type: services will restart, mounts will unmount and re-mount, etc. Not |
| 234 | + all types can refresh.) |
| 235 | + |
| 236 | +This is one of the four relationship metaparameters, along with |
| 237 | +`before`, `require`, and `notify`. For more context, including the |
| 238 | +alternate chaining arrow (`->` and `~>`) syntax, see |
| 239 | +[the language page on relationships](https://puppet.com/docs/puppet/latest/lang_relationships.html). |
| 240 | + |
| 241 | +### tag |
| 242 | + |
| 243 | +Add the specified tags to the associated resource. While all resources |
| 244 | +are automatically tagged with as much information as possible |
| 245 | +(e.g., each class and definition containing the resource), it can |
| 246 | +be useful to add your own tags to a given resource. |
| 247 | + |
| 248 | +Multiple tags can be specified as an array: |
| 249 | + |
| 250 | + file {'/etc/hosts': |
| 251 | + ensure => file, |
| 252 | + source => 'puppet:///modules/site/hosts', |
| 253 | + mode => '0644', |
| 254 | + tag => ['bootstrap', 'minimumrun', 'mediumrun'], |
| 255 | + } |
| 256 | + |
| 257 | +Tags are useful for things like applying a subset of a host's configuration |
| 258 | +with [the `tags` setting](https://puppet.com/docs/puppet/latest/configuration.html#tags) |
| 259 | +(e.g. `puppet agent --test --tags bootstrap`). |
| 260 | + |
0 commit comments