Search code examples
puppet

Puppet mount type: append option attribute value


I am trying to append the option nosgid to the /dev/shm mount in the /etc/fstab file. How can I append this value to the existing options in the file? I get an error when I try to run the following code.

class osharden {
  mount { "/dev/shm" :
    device  => 'tmpfs',
    options +> 'nosgid',
    fstype  => tmpfs,
  }
}

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Syntax error at '+>'; expected '}' at /etc/puppet/modules/osharden/manifests/init.pp:4 on node


Solution

  • The plussignment operator (+>) applies only to appending values to an array-valued attribute in the context of overriding properties of an already-declared resource. The options attribute of the Mount resource type takes a single string as its value, and you're trying to use plussignment in the regular declaration of your resource, not an override. In other words, plussignment is no way going to work for this task.

    Information about the current state of a target system is conveyed to the Puppet catalog compiler via node facts. If, as you say here, you want Puppet to take the previous mount options into account then you'll need to write a custom or external fact with which to convey that information to the catalog compiler. Puppet itself can distribute the fact code to clients. You would then compute the desired option value based on the initial options, including nosgid, and manage the mount options to have the computed value.

    Note that that's more complicated than just appending ",nosgid", for you don't want to append that option again if it's already there, and you may want to avoid sgid and nosgid both being included in the options. You may also want to avoid results such as "defaults,nosgid".

    Honestly, I think all that is probably more trouble than it's worth. I'd recommend managing the mount option string, without regard to its original value. For example:

    mount { "/dev/shm" :
      ensure  => 'mounted',
      device  => 'tmpfs',
      options => 'rw,nosuid,nosgid,dev,exec,async',
      fstype  => 'tmpfs',
      atboot  => 1,
      pass    => 0,
    }