ansible/ansible · error · CronTabError

Unexpected error:

Error message

Unexpected error:

What it means

Error "Unexpected error:" thrown in ansible/ansible.

Source

Thrown at lib/ansible/modules/cron.py:277

                self.b_cron_file = os.path.join(b'/etc/cron.d', to_bytes(cron_file, errors='surrogate_or_strict'))
        else:
            self.cron_file = None

        self.read()

    def read(self):
        # Read in the crontab from the system
        if self.cron_file:
            # read the cronfile
            try:
                with open(self.b_cron_file, 'rb') as f:
                    self.n_existing = to_native(f.read(), errors='surrogate_or_strict')
                    self.lines = self.n_existing.splitlines()
            except OSError:
                # cron file does not exist
                return
            except Exception:
                raise CronTabError("Unexpected error:", sys.exc_info()[0])
        else:
            # FIXME: using safely quoted shell for now, but this really should be two non-shell calls instead.
            (rc, out, err) = self.module.run_command(self._read_user_execute(), use_unsafe_shell=True)

            if rc not in (0, 1):  # 1 can mean that there are no jobs.
                raise CronTabError("Unable to read crontab")

            self.n_existing = out

            lines = out.splitlines()
            count = 0
            for l in lines:
                if count > 2 or (not re.match(r'# DO NOT EDIT THIS FILE - edit the master and reinstall.', l) and
                                 not re.match(r'# \(/tmp/.*installed on.*\)', l) and
                                 not re.match(r'# \(.*version.*\)', l)):
                    self.lines.append(l)
                else:
                    pattern = re.escape(l) + '[\r\n]?'

View on GitHub (pinned to 9cf16a4aca)

Solutions

  1. Run with -vvv to see the underlying cron error.
  2. Check that cron is installed and the user has permission to edit crontabs.

When it happens

Trigger: Thrown at lib/ansible/modules/cron.py:277 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of ansible/ansible@9cf16a4aca (2026-08-15). Data as JSON: /api/errors/4c801e57e5ae8c41. Report an issue: GitHub.