# copy module with force=no intermittently reports "ok" status even when destination file does not exist

**URL:** <https://forum.ansible.com/t/copy-module-with-force-no-intermittently-reports-ok-status-even-when-destination-file-does-not-exist/14793>\
**Category:** Ansible Project\
**Created:** [March 17, 2014, 5:29pm UTC](https://forum.ansible.com/t/copy-module-with-force-no-intermittently-reports-ok-status-even-when-destination-file-does-not-exist/14793 "2014-03-17T17:29:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Banks](https://avatars.discourse-cdn.com/v4/letter/d/3e96dc/32.png) [@David\_Banks](https://forum.ansible.com/u/David_Banks)\
**Post date:** [March 17, 2014, 5:29pm UTC](https://forum.ansible.com/t/copy-module-with-force-no-intermittently-reports-ok-status-even-when-destination-file-does-not-exist/14793/1 "2014-03-17T17:29:10Z")

</div>

Hey there,

I am spawning some VMs using vagrant (CentOS 6.5 images) and copying a file to them. I only want to copy the file if it does not already exist, so that I can repeatedly run my playbooks against the host.

My copy task looks like this:

- name: Upload the default iptables configuration  
copy: src=iptables.cf dest=/etc/sysconfig/iptables force=no  
sudo: yes

Roughly every 1 in 4 runs – when reproducing on a fresh VM using “vagrant destroy -f myvm; vagrant up myvm; ansible-playbook -i myinventory playbook.yml” – the ‘copy’ module will report an ‘ok’ status and _not_ copy in the file, despite the fact that the file definitely did not exist when the task was run. The rest of the time the task will correctly report a ‘changed’ status and correctly copy the file.

I was unable to reproduce this when running against localhost. However, the behaviour is not dependent on the choice of destination file. I can try “/tmp/nonexistent-file-i-made-up” and it will reproduce with the same frequency. This makes me think that it’s not due to a timing issue in the VM boot, as was my first thought.

I have no idea why this would happen, or how I can debug further, does anyone have an idea?

I am working around it by doing an explicit check before:

- name: Check for iptables configuration existence  
action: stat path=/etc/sysconfig/iptables  
register: iptables\_stat

- name: Upload the default iptables configuration  
copy: src=iptables.cf dest=/etc/sysconfig/iptables  
sudo: yes  
when: not iptables\_stat.stat.exists

This doesn’t have the same issue, although it does have the obvious race condition.

Dave

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [March 21, 2014, 1:36pm UTC](https://forum.ansible.com/t/copy-module-with-force-no-intermittently-reports-ok-status-even-when-destination-file-does-not-exist/14793/2 "2014-03-21T13:36:02Z")

</div>

" the ‘copy’ module will report an ‘ok’ status and _not_ copy in the file, despite the fact that the file definitely did not exist when the task was run. "

I’m highly skeptical here but it’s not quite fair for me to claim server gremlins without first using the server gremlins detector, which I don’t have.

Can you see if you can get to the bottom of why it is happening?
