Puppet Function: join_mount_opts
- Defined in:
- lib/puppet/parser/functions/join_mount_opts.rb
- Function type:
- Ruby 3.x API
Overview
Merge two sets of mount
options in a reasonable fashion.
The second set will always override the first.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/puppet/parser/functions/join_mount_opts.rb', line 2 newfunction(:join_mount_opts, :type => :rvalue, :doc => <<-EOM) do |args| # Input Validation Merge two sets of `mount` options in a reasonable fashion. The second set will always override the first. @return [Array[String]] EOM if not args[0].is_a?(Array) or not args[1].is_a?(Array) then raise Puppet::ParseError.new("You must pass two arrays to join!") end # Variable Assignment system_opts = args[0].flatten.map(&:strip) new_opts = args[1].flatten.map(&:strip) # Remove any items that have a corresponding 'no' item in the # list. Such as 'dev' vs 'nodev', etc... system_opts.delete_if{|x| new_opts.include?("no#{x}") } # Reverse this if the user wants to explicitly set an option and a no* # option is already present. system_opts.delete_if{|x| found = false if x =~ /^no(.*)/ then found = new_opts.include?($1) end found } = {} if !lookupvar('::selinux_current_mode') or lookupvar('::selinux_current_mode') == 'disabled' then # SELinux is off, get rid of selinux related items in the # new_opts. system_opts.delete_if{|x| x =~ /^(((fs|def|root)?context=)|seclabel)/ } new_opts.delete_if{|x| x =~ /^(((fs|def|root)?context=)|seclabel)/ } else # Remove any SELinux context items if 'seclabel' is set. This # means that we can't remount it with new options. if system_opts.include?('seclabel') then # These two aren't compatible for remounts and can cause # issues unless done *very* carefully. system_opts.delete_if{|x| x =~ /^(fs|def|root)?context=/ } new_opts.delete_if{|x| x =~ /^(fs|def|root)?context=/ } end end (system_opts + new_opts).each do |opt| k,v = opt.split('=') if v and v.include?('"\'') then v.delete('"\'') # Anything with a comma must be double quoted! v = '"' + v + '"' if v.include?(',') end [k] = v end retval = [] .keys.sort.each do |k| if [k] then retval << "#{k}=#{[k]}" else retval << k end end retval.join(',') end |