title: Ansible copy or move files only on remote host
body: <p>This should work but doesn't and gives the following error (below).  </p>
  
  <p>I've read a couple of posts on stackoverflow <a href="https://stackoverflow.com/questions/24162996/how-to-move-rename-a-file-using-an-ansible-task-on-a-remote-system/24165405#24165405">here</a> and <a href="https://stackoverflow.com/questions/28483031/move-files-on-remote-system-only-if-destination-doesnt-exist-with-ansible">here</a> but there doesn't seem to be a good answer that works in this case.  I'm really hoping I'm just missing something dumb and I have been at this for hours so please don't mind my snark but I need to vent.</p>
  
  <p>Since ansible, 2.3.0, can't do something as simple as copy/move/rename files ONLY on the remote host, I'm mean who would want to do that?  And it also can't act on globs (*) (say when you don't know what files to act on), a 2 step approach seems to be the only way (that I know of) to move some files (only on the remote host).  But not even this works.</p>
  
  <h1>migrate_rhel2centos.yml</h1>
  
  <pre><code>---
  - hosts: RedHat
    become: true
    become_user: root
    become_method: sudo
    vars:
      repo_dir: /etc/yum.repos.d
    tasks:
    - name: create directory
      file: path=/etc/yum.repos.d/bak/ state=directory
  
    - name: get repo files
      shell: "ls {{ repo_dir }}/*.repo"
      register: repo_list
  
   - debug: var=repo_list.stdout_lines
  
   - name: move repo files  
     command: "/bin/mv -f {{ item }} bak"
     args:  
       chdir: "{{repo_dir}}"
     with_items: repo_list.stdout_lines
  
  
  #################################
  
  TASK [get repo files]     
  
  **********************************************************************
  changed: [myhost]
  
  TASK [debug]    
  **********************************************************************
  ok: [myhost] =&gt; {
       "repo_list.stdout_lines": [
       "/etc/yum.repos.d/centric.repo", 
       "/etc/yum.repos.d/redhat.repo", 
       "/etc/yum.repos.d/rhel-source.repo"
     ]
  }
  
  TASK [move repo files]   
  *******************************************************************
  failed: [myhost] (item=repo_list.stdout_lines) =&gt; {"changed": true,    "cmd": ["/bin/mv", "-f", "repo_list.stdout_lines", "bak"], "delta": "0:00:00.001945", "end": "2016-12-13 15:07:14.103823", "failed": true, "item": "repo_list.stdout_lines", "rc": 1, "start": "2016-12-13 15:07:14.101878", "stderr": "/bin/mv: cannot stat `repo_list.stdout_lines': No such file or directory", "stdout": "", "stdout_lines": [], "warnings": []}
  to retry, use: --limit @/home/jimm/.ansible/migrate_rhel2centos.retry
  
  PLAY RECAP 
  ********************************
  myhost : ok=5    changed=1    unreachable=0    failed=1   
  </code></pre>