puppetlabs/puppet · error · FileReadError

Could not write crontab for

Error message

Could not write crontab for %{path}: %{detail}

What it means

Raised as FileReadError by the SunOS (suntab) filetype's write method (lib/puppet/util/filetype.rb:299) when any step of installing the new crontab fails: writing the temp file, chowning it to user %{path}, or running 'crontab <tempfile>'. The underlying OS error is included as %{detail}; the temp file is always cleaned up in ensure.

Solutions

  1. Inspect %{detail} to identify which step failed (temp file write, chown, or crontab install).
  2. Verify the user %{path} exists (uid lookup succeeds) before writing its crontab.
  3. Check disk space and permissions in the temp directory used by Tempfile.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at lib/puppet/util/filetype.rb:299 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21). Data as JSON: /api/errors/087778f890b06e52. Report an issue: GitHub.

Appendix: source

Thrown at lib/puppet/util/filetype.rb:299

    def remove
      Puppet::Util::Execution.execute(%w[crontab -r], cronargs)
    rescue => detail
      raise FileReadError, _("Could not remove crontab for %{path}: %{detail}") % { path: @path, detail: detail }, detail.backtrace
    end

    # Overwrite a specific @path's cron tab; must be passed the @path name
    # and the text with which to create the cron tab.
    def write(text)
      # this file is managed by the OS and should be using system encoding
      output_file = Tempfile.new("puppet_suntab", :encoding => Encoding.default_external)
      begin
        output_file.print text
        output_file.close
        # We have to chown the stupid file to the user.
        File.chown(Puppet::Util.uid(@path), nil, output_file.path)
        Puppet::Util::Execution.execute(["crontab", output_file.path], cronargs)
      rescue => detail
        raise FileReadError, _("Could not write crontab for %{path}: %{detail}") % { path: @path, detail: detail }, detail.backtrace
      ensure
        output_file.close
        output_file.unlink
      end
    end
  end

  #  Support for AIX crontab with output different than suntab's crontab command.
  newfiletype(:aixtab) do
    # Read a specific @path's cron tab.
    def read
      unless Puppet::Util.uid(@path)
        Puppet.debug _("The %{path} user does not exist. Treating their crontab file as empty in case Puppet creates them in the middle of the run.") % { path: @path }

        return ""
      end

      Puppet::Util::Execution.execute(%w[crontab -l], cronargs)

View on GitHub (pinned to e227c27540)