copy module bug?

63 views
Skip to first unread message

Oscar Hodgson

unread,
Jun 27, 2016, 2:46:24 PM6/27/16
to Ansible Project

Ansible 2.2.0

Copy module documentation says, "Options / force: the default is yes, which will replace the remote file when contents are different than the source. If no, the file will only be transferred if the destination does not exist."

A sample playbook:

---

- hosts: localhost

  tasks:
    - file:
        dest: "{{ item }}"
        state: absent
      with_items:
        - /tmp/passwd
        - /tmp/ntp.conf

    - copy: 
        src: "{{ item.src }}"
        dest: /tmp
        force: "{{ item.force }}"
      with_items:
        - { src: /etc/passwd, force: yes }
        - { src: /etc/ntp.conf, force: no }

    - command: 'ls /tmp/passwd /tmp/ntp.conf'

The documentation leads me to believe that /tmp/ntp.conf should be present at the end of this play.  Am I missing something?

Oscar

Kai Stian Olstad

unread,
Jun 27, 2016, 4:05:34 PM6/27/16
to ansible...@googlegroups.com
If you run ansible-playbook with -v you'll see this message
"dest": "/tmp",
"msg": "file already exists",

So the destination /tmp do exist and the ntp.conf is not created.
If you set the "dest: /tmp/" (trailing slash) and you run
ansible-playbook with -v you get this
"dest": "/tmp/ntp.conf"
and it work as you expected.

If it's a feature or a bug I don't know, I guess it's a feature.

--
Kai Stian Olstad

Oscar Hodgson

unread,
Jun 27, 2016, 6:39:41 PM6/27/16
to Ansible Project, ansible-pr...@olstad.com


On Monday, June 27, 2016 at 4:05:34 PM UTC-4, Kai Stian Olstad wrote:

If you run ansible-playbook with -v you'll see this message
   "dest": "/tmp",
   "msg": "file already exists",

So the destination /tmp do exist and the ntp.conf is not created.
If you set the "dest: /tmp/" (trailing slash) and you run
ansible-playbook with -v you get this
   "dest": "/tmp/ntp.conf"
and it work as you expected.

If it's a feature or a bug I don't know, I guess it's a feature.

--
Kai Stian Olstad

Duh.  So I was missing something. <g>.  Thanks.

Oscar 
Reply all
Reply to author
Forward
0 new messages