community.general icon indicating copy to clipboard operation
community.general copied to clipboard

The archive module executes without errors for non-existent files

Open navisk13 opened this issue 4 months ago • 3 comments

Summary

Giving an invalid or non-existent file name or path to the path parameter of the archive module still executes the playbook successfully without throwing an error.

Issue Type

Bug Report

Component Name

archive

Ansible Version

$ ansible --version
ansible [core 2.17.4]
  config file = None
  configured module search path = ['/home/ubuntu/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ubuntu/.local/lib/python3.12/site-packages/ansible
  ansible collection location = /home/ubuntu/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/ubuntu/.local/bin/ansible
  python version = 3.12.3 (main, Sep 11 2024, 14:17:37) [GCC 13.2.0] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general
# /home/ubuntu/.local/lib/python3.12/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 9.4.0  

# /usr/lib/python3/dist-packages/ansible_collections
Collection        Version
----------------- -------
community.general 8.3.0  

Configuration

$ ansible-config dump --only-changed
ANSIBLE_NOCOWS(env: ANSIBLE_NOCOWS) = True
CONFIG_FILE() = None
DEFAULT_VAULT_PASSWORD_FILE(env: ANSIBLE_VAULT_PASSWORD_FILE) = /home/ubuntu/.vault_pass.txt

OS / Environment

Target OS: Ubuntu 24.04.1 LTS running in Docker

Steps to Reproduce

- name: Test archive
  hosts: ubuntu1
  become: true
  vars_files:
    - vault.yml
  tasks:
    - name: Compress file into an archive
      community.general.archive:
        path: a/random/nonexistent/file
        format: zip

The command used to run the playbook: ansible-playbook -i inventory.ini playbook.yml

Expected Results

I expected Ansible to raise an error indicating that the file I was attempting to compress into a ZIP file could not be found.

Actual Results

The playbook executes successfully without any errors, even when an invalid file path is provided. While no changes are applied, the absence of an error message can lead to confusion, especially in larger playbooks. Users might assume the action was completed successfully, overlooking the fact that the file was not found and the intended operation did not occur.

ok: [ubuntu1] => {
    "archived": [],
    "arcroot": "a/random/nonexistent/",
    "changed": false,
    "dest": "a/random/nonexistent/file.zip",
    "dest_state": "absent",
    "expanded_exclude_paths": [],
    "expanded_paths": [
        "a/random/nonexistent/file"
    ],
    "invocation": {
        "module_args": {
            "attributes": null,
            "dest": null,
            "exclude_path": [],
            "exclusion_patterns": null,
            "force_archive": false,
            "format": "zip",
            "group": null,
            "mode": null,
            "owner": null,
            "path": [
                "a/random/nonexistent/file"
            ],
            "remove": false,
            "selevel": null,
            "serole": null,
            "setype": null,
            "seuser": null,
            "unsafe_writes": false
        }
    },
    "missing": [
        "a/random/nonexistent/file"
    ]
}

Code of Conduct

  • [X] I agree to follow the Ansible Code of Conduct

navisk13 avatar Oct 11 '24 01:10 navisk13