#81569·ansible

copy module in check mode fails to populate the dest/path attributes of the registered variable

Author: erempelCreated Aug 23, 2023Updated Sep 11, 2026
Labelsbughas_prP3affects_2.14

Summary

when using the copy module in check mode, if the file would be updated, the registered variable does not contain the same attributes as it would if the file is not updated, or is not run in check mode. Failure to register the same attributes results in other parts of the playbook to fail on undefined values.

changed file in check mode registers

{ "changed": true, "diff": [ { "before": "xxxx", "after": "yyyy" } ], failed": false } but if the file will not be changed the registered variable contains

{ "changed": false, "checksum": "692cb32b7636c2595d506af848cb666478f60acc", "dest": "/some/path/to/file", "diff": { "after": { "path": "/some/path/to/file" }, "before": { "path": "/some/path/to/file" } }, "failed": false, "gid": 0, "group": "root", "mode": "0440", "owner": "root", "path": "/some/path/to/file", "size": 1679, "state": "file", "uid": 0 }

Issue Type

Bug Report

Component Name

ansible.core.copy

Ansible Version

$ ansible --version
ansible [core 2.14.2]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.11/site-packages/ansible
  ansible collection location = /home/user/.ansible
  executable location = /usr/bin/ansible
  python version = 3.11.2 (main, Jun  6 2023, 07:39:01) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] (/usr/bin/python3.11)
  jinja version = 3.1.2
  libyaml = True

Configuration

# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all

CONFIG_FILE() = /etc/ansible/ansible.cfg
DEFAULT_HOST_LIST(/etc/ansible/ansible.cfg) = ['/etc/ansible/inventory.sh']
DEFAULT_LOG_PATH(/etc/ansible/ansible.cfg) = /var/log/ansible.log
DEFAULT_PRIVATE_KEY_FILE(/etc/ansible/ansible.cfg) = /etc/ansible/ansible_rsa
DEFAULT_VAULT_PASSWORD_FILE(/etc/ansible/ansible.cfg) = /etc/ansible/.passfile
DEPRECATION_WARNINGS(/etc/ansible/ansible.cfg) = False
RETRY_FILES_ENABLED(/etc/ansible/ansible.cfg) = False
SYSTEM_WARNINGS(/etc/ansible/ansible.cfg) = False

CONNECTION:
==========

ssh:
___
pipelining(/etc/ansible/ansible.cfg) = False
private_key_file(/etc/ansible/ansible.cfg) = /etc/ansible/ansible_rsa

OS / Environment

[xerr@aardwolf roles]$ cat /etc/redhat-release Red Hat Enterprise Linux release 8.8 (Ootpa)

Steps to Reproduce

invoke a playbook with --check that uses a copy module to place a file with a "register: varname" directive. Then review the contents of the varname for files that would be changed, and for files that would not be changed.

Expected Results

The registered variable should have the same attributes, possibly with different values, in check mode and not in check mode.

Actual Results

many of the attributes are not present for files that would be changed if not running in check mode.

Code of Conduct

  • I agree to follow the Ansible Code of Conduct