Skip to content

Copy module bug when a directory exists with the same name as a file in src directory #25792

@sourcejedi

Description

@sourcejedi
ISSUE TYPE
  • Bug Report
COMPONENT NAME

copy module

ANSIBLE VERSION
ansible 2.4.0 (devel 91e995d691) last updated 2017/06/14 08:27:05 (GMT +100)
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/alan-sysop/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/alan-sysop/src/ansible/lib/ansible
  executable location = /home/alan-sysop/src/ansible/bin/ansible
  python version = 2.7.13 (default, May 10 2017, 20:04:28) [GCC 6.3.1 20161221 (Red Hat 6.3.1-1)]
CONFIGURATION

Tested with -c local.

OS / ENVIRONMENT

N/A

SUMMARY

When a directory exists with the same name as a file in src directory, the copy module does the wrong thing. (It should simply fail, like cp -r does (cp: cannot overwrite directory 'dest' with non-directory)).

STEPS TO REPRODUCE
# test.yml
- hosts: all
  tasks:
  - copy:
      src: src/
      dest: /tmp/dest
mkdir src
touch src/a

mkdir /tmp/dest
mkdir /tmp/dest/a
ansible-playbook -c local -i localhost, test.yml
tree /tmp/dest

# WARNING rm -r
rm -r  /tmp/dest

mkdir /tmp/dest
mkdir /tmp/dest/a
mkdir /tmp/dest/a/a
ansible-playbook -c local -i localhost, test.yml
EXPECTED RESULTS

Both of the above ansible commands should fail, with an error message similar to cp -r, cp: cannot overwrite directory 'a' with non-directory.

ACTUAL RESULTS
PLAY [all] *********************************************************************

TASK [Gathering Facts] *********************************************************
ok: [localhost]

TASK [copy] ********************************************************************
changed: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0   

/tmp/dest
└── a
    └── a

PLAY [all] *********************************************************************

TASK [Gathering Facts] *********************************************************
ok: [localhost]

TASK [copy] ********************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709", "failed": true,
"msg": "attempted to take checksum of directory: /tmp/dest/a/a"}
	to retry, use: --limit @/home/alan-sysop/t/test.retry

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1   

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Priority 3 - Approved, No Time Limitationaffects_2.4This issue/PR affects Ansible v2.4bugThis issue/PR relates to a bug.filesFiles categoryhas_prThis issue has an associated PR.moduleThis issue/PR relates to a module.needs_infoThis issue requires further information. Please answer any outstanding questions.support:coreThis issue/PR relates to code supported by the Ansible Engineering Team.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions