Skip to content

cronvar: module fails to handle empty string variables consistently across platforms #10439

@gdrosos

Description

@gdrosos

Summary

The cronvar module allows setting environment variables with an empty string value (e.g., value: ''), which succeeds on some operating systems (e.g., Fedora 42) but fails on others (e.g., Ubuntu 22.04) due to differences in crontab validation.

While this is likely an edge case, the inconsistency indicates a portability concern in how the module handles input across cron implementations. It might be worth documenting the limitation or introducing input validation to prevent hard-to-debug failures on certain platforms.

This issue was identified as part of a research project focused on improving the reliability and portability of Ansible modules.

Issue Type

Bug Report

Component Name

cronvar

Ansible Version

$ ansible --version
ansible [core 2.18.6]
  python version = 3.12.3 
  jinja version = 3.1.6
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general
Collection        Version
----------------- -------
community.general 11.1.0 

Configuration

$ ansible-config dump --only-changed

OS / Environment

Success (task status: changed):

  • Fedora (40, 41, 42)
  • Alpine (3.20.6, 3.21.3)
  • RHEL (9)
  • Arch Linux (latest)
  • Rocky Linux (9.3)
  • openSUSE Leap/Tumbleweed

Failure (task status: ignored, due to crontab error):

  • Ubuntu (22.04, 24.04)
  • Debian (11, 12)

Steps to Reproduce

        "community.general.cronvar": {
          "name": "EMPTY_VAR",
          "value": "",
          "user": "root"
        }

Expected Results

The task could exhibit uniform behavior across all supported OSes, such as consistently rejecting invalid inputs like empty strings (value: '') in order to prevent hard-to-debug failures on certain platforms.

Actual Results

On Ubuntu and Debian, the task fails with:

TASK [cronvar : Add EMPTY_VAR to root crontab] *********************************
fatal: [testhost]: FAILED! => {"changed": false, "msg": "\"/tmp/crontabt7qo4n8_\":0: bad minute\nerrors in crontab file, can't install.\n"}
...ignoring

while on the other Operating Systems it succeeds:

TASK [cronvar : Add EMPTY_VAR to root crontab] *********************************
changed: [testhost]

Code of Conduct

  • I agree to follow the Ansible Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue/PR relates to a bughas_prmodulemodulepluginsplugin (any type)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions