This should work but doesn't and gives the following error (below).
I've read a couple of posts on stackoverflow here and here 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.
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.
migrate_rhel2centos.yml
---
- 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] => {
     "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) => {"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   
 
     
     
     
    