title: Ansible: Copying files from local to remote - "AttributeError: 'dict' object has no attribute 'endswith'"
body: <p>I am trying to copy files (scripts and rpms) stored locally to a set of servers. I can copy the files when the names are hard coded, but not when I am using a variable. </p>
  
  <p>ansible-lint comes back with no errors.</p>
  
  <p>When use variable replacement I get the error:</p>
  
  <pre><code>TASK [Copy cpu_gov.sh] 
  ***************************************************************************************************************************************************************
  An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'dict' object has no attribute 'endswith'
  fatal: [ceph3]: FAILED! =&gt; {"msg": "Unexpected failure during module execution.", "stdout": ""}
  </code></pre>
  
  <p>In debug mode I can see that it is a Python error on a trailing "/". All other uses of the variable work fine, only when it is in the ""src:" field does it fail. </p>
  
  <pre><code>The full traceback is:
  Traceback (most recent call last):
    File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 145, in run
      res = self._execute()
    File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 650, in _execute
      result = self._handler.run(task_vars=variables)
    File "/usr/lib/python2.7/site-packages/ansible/plugins/action/copy.py", line 461, in run
      trailing_slash = source.endswith(os.path.sep)
  AttributeError: 'dict' object has no attribute 'endswith'
  
  fatal: [ceph3]: FAILED! =&gt; {
      "msg": "Unexpected failure during module execution.",
      "stdout": ""
  }
  </code></pre>
  
  <pre><code>---
  ### Test
  #
  
  - hosts: all
  
    vars:
     #isdct_rpm: foobar.txt
     isdct_rpm: isdct-3.0.16-1.x86_64.rpm
     cpu_gov: cpu_gov.sh
     irq_bal: irq_balance.sh
     root_dir: /root
     bin_dir: /root/bin
     files_dir: /root/projects/ansible/bootstrap/files
  
    remote_user: root
    tasks:
  </code></pre>
  
  <p>These work just fine -</p>
  
  <pre><code>
    - name: ISDCT rpm exists?
      stat:
        path: "{{ root_dir }}/{{ isdct_rpm }}"
      register: isdct_rpm
      tags:
         - tools
  
    - name: cpu_gov exists?
      stat:
        path: "{{ bin_dir }}/{{ cpu_gov }}"
      register: cpu_gov
      tags:
         - tools
  
    - name: irq_balance exists?
      stat:
        path: "{{ bin_dir }}/{{ irq_bal }}"
      register: irq_bal
      tags:
         - tools
  </code></pre>
  
  <p>The first task is the failing one:</p>
  
  <pre><code>  - name:  Copy ISDCT rpm
      copy:
        remote_src: no
        src: "{{ isdct_rpm }}"
        dest: "{{ root_dir }}"
      when: not isdct_rpm.stat.exists
  </code></pre>
  
  <p>These work fine:</p>
  
  <pre><code>  - name:  Copy rpm
      copy:
        remote_src: no
        src: isdct-3.0.16-1.x86_64.rpm
        dest: /root
      when: not isdct_rpm.stat.exists
  
    - name:  Copy cpu_gov.sh
      copy:
        remote_src: no
        src: cpu_gov.sh
        # - fails - src: "{{ cpu_gov }}"
        dest: "{{ bin_dir }}"
      when: not cpu_gov.stat.exists
  
    - name:  Copy irq_balance.sh
      copy:
        remote_src: no
        src: irq_balance.sh
        dest: /root
      when: not irq_bal.stat.exists
  </code></pre>
  
  <pre><code>The full traceback is:
  Traceback (most recent call last):
    File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 145, in run
      res = self._execute()
    File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 650, in _execute
      result = self._handler.run(task_vars=variables)
    File "/usr/lib/python2.7/site-packages/ansible/plugins/action/copy.py", line 461, in run
      trailing_slash = source.endswith(os.path.sep)
  AttributeError: 'dict' object has no attribute 'endswith'
  
  fatal: [ceph3]: FAILED! =&gt; {
      "msg": "Unexpected failure during module execution.",
      "stdout": ""
  }
  </code></pre>