lib/puppet/provider/mobileconfig.rb
def coalesce_mobileconfig

    if @property_flush[:ensure] == :absent

      # Remove the profile
      id = @resource[:name]
      begin
        profiles(['-R', '-p', id])
      rescue Puppet::ExecutionFailure => e
        raise Puppet::Error, "#mobileconfig: command returned
          non-zero `profiles -R -p #{id}`"
      end

    else
      # Create a tmp dir we can use to house the .mobileconfig
      path = [Dir.mktmpdir, "#{SecureRandom.hex}.mobileconfig"].join("/")

      # Transform @resource into usable Hash
      document = {
        'PayloadIdentifier'        => @resource[:name],
        'PayloadDescription'       => @resource[:description],
        'PayloadDisplayName'       => @resource[:displayname],
        'PayloadOrganization'      => @resource[:organization],
        'PayloadRemovalDisallowed' =>
          @resource[:removaldisallowed] == :false ? false : true,
        'PayloadScope'             => 'System',
        'PayloadType'              => 'Configuration',
        'PayloadUUID'              => SecureRandom.uuid,
        'PayloadVersion'           => 1,
        'PayloadContent'           => transform_content(@resource[:content]),
      }

      # Parse the document Hash and create new plist file
      plist       = CFPropertyList::List.new
      plist.value = CFPropertyList.guess(document)
      plist.save(path, CFPropertyList::List::FORMAT_XML)

      begin
        profiles(['-I', '-F', path])
      rescue Puppet::ExecutionFailure => e
        raise Puppet::Error, "#mobileconfig: command returned non-zero
          `profiles -I -F #{path}`"
      end

      FileUtils.rm_rf path if File.exists? path
    end

  end
# Provider Helper method
# Build and install the mobileconfig OR destroy it
Provider Helper method
Build and install the mobileconfig OR destroy it
Provider Helper method Build and install the mobileconfig OR destroy it
def coalesce_mobileconfig
    if @property_flush[:ensure] == :absent
      id = @resource[:name]
      begin
        profiles(['-R', '-p', id])
      rescue Puppet::ExecutionFailure => e
        raise Puppet::Error, "#mobileconfig: command returned
          non-zero `profiles -R -p #{id}`"
      end
    else
      path = [Dir.mktmpdir, "#{SecureRandom.hex}.mobileconfig"].join("/")
      document = {
        'PayloadIdentifier'        => @resource[:name],
        'PayloadDescription'       => @resource[:description],
        'PayloadDisplayName'       => @resource[:displayname],
        'PayloadOrganization'      => @resource[:organization],
        'PayloadRemovalDisallowed' =>
          @resource[:removaldisallowed] == :false ? false : true,
        'PayloadScope'             => 'System',
        'PayloadType'              => 'Configuration',
        'PayloadUUID'              => SecureRandom.uuid,
        'PayloadVersion'           => 1,
        'PayloadContent'           => transform_content(@resource[:content]),
      }
      plist       = CFPropertyList::List.new
      plist.value = CFPropertyList.guess(document)
      plist.save(path, CFPropertyList::List::FORMAT_XML)
      begin
        profiles(['-I', '-F', path])
      rescue Puppet::ExecutionFailure => e
        raise Puppet::Error, "#mobileconfig: command returned non-zero
          `profiles -I -F #{path}`"
      end
      FileUtils.rm_rf path if File.exists? path
    end
  end
def coalesce_mobileconfig if @property_flush [ :ensure ] == :absent id = @resource [ :name ] begin profiles ( [ '-R' , '-p' , id ] ) rescue Puppet :: ExecutionFailure => e raise Puppet :: Error , "#mobileconfig: command returned
          non-zero `profiles -R -p #{id}`" end else path = [ Dir . mktmpdir , "#{SecureRandom.hex}.mobileconfig" ] . join ( "/" ) document = { 'PayloadIdentifier' => @resource [ :name ] , 'PayloadDescription' => @resource [ :description ] , 'PayloadDisplayName' => @resource [ :displayname ] , 'PayloadOrganization' => @resource [ :organization ] , 'PayloadRemovalDisallowed' => @resource [ :removaldisallowed ] == :false ? false : true , 'PayloadScope' => 'System' , 'PayloadType' => 'Configuration' , 'PayloadUUID' => SecureRandom . uuid , 'PayloadVersion' => 1 , 'PayloadContent' => transform_content ( @resource [ :content ] ) , } plist = CFPropertyList :: List . new plist . value = CFPropertyList . guess ( document ) plist . save ( path , CFPropertyList :: List :: FORMAT_XML ) begin profiles ( [ '-I' , '-F' , path ] ) rescue Puppet :: ExecutionFailure => e raise Puppet :: Error , "#mobileconfig: command returned non-zero
          `profiles -I -F #{path}`" end FileUtils . rm_rf path if File . exists? path end end
Provider Helper method
Build and install the mobileconfig OR destroy it
Provider Helper method Build and install the mobileconfig OR destroy it
# Remove the profile # Create a tmp dir we can use to house the .mobileconfig # Transform @resource into usable Hash # Parse the document Hash and create new plist file