<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">copy</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.4.2.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/user/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.14+ (default, Dec  5 2017, 15:17:02) [GCC 7.2.0]
"><pre class="notranslate"><code class="notranslate">ansible 2.4.2.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/user/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.14+ (default, Dec  5 2017, 15:17:02) [GCC 7.2.0]

</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<p dir="auto">default configuration</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>

<p dir="auto">Linux / Linux</p>
<h5 dir="auto">SUMMARY</h5>

<p dir="auto">The copy module copies only directories, no files. The directories look fine and are created recursively, however no files are copied. If you run the playbook again then the files too are copied.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ find . -ls
   852461      4 drwxr-xr-x   3 user     user         4096 Jan 15 14:00 .
   852463      4 drwxr-xr-x   4 user     user         4096 Jan 15 13:59 ./source
   860161      4 drwxr-xr-x   2 user     user         4096 Jan 15 13:59 ./source/one
   846271      4 -rw-r--r--   1 user     user            4 Jan 15 13:59 ./source/one/afile
   942425      4 drwxr-xr-x   2 user     user         4096 Jan 15 13:59 ./source/two
   846272      4 -rw-r--r--   1 user     user          121 Jan 15 14:00 ./test.yml
$ ansible-playbook test.yml
 [WARNING]: Unable to parse /etc/ansible/hosts as an inventory source

 [WARNING]: No inventory was parsed, only implicit localhost is available

 [WARNING]: Could not match supplied host pattern, ignoring: all

 [WARNING]: provided hosts list is empty, only localhost is available


PLAY [localhost] *****************************************************************************************

TASK [copy] **********************************************************************************************
changed: [localhost]

PLAY RECAP ***********************************************************************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=0   

$ find . -ls
   852461      4 drwxr-xr-x   4 user     user         4096 Jan 15 14:01 .
   852463      4 drwxr-xr-x   4 user     user         4096 Jan 15 13:59 ./source
   860161      4 drwxr-xr-x   2 user     user         4096 Jan 15 13:59 ./source/one
   846271      4 -rw-r--r--   1 user     user            4 Jan 15 13:59 ./source/one/afile
   942425      4 drwxr-xr-x   2 user     user         4096 Jan 15 13:59 ./source/two
   942429      4 drwxr-xr-x   3 user     user         4096 Jan 15 14:01 ./target
   942430      4 drwxr-xr-x   4 user     user         4096 Jan 15 14:01 ./target/source
   942431      4 drwxr-xr-x   2 user     user         4096 Jan 15 14:01 ./target/source/one
   942432      4 drwxr-xr-x   2 user     user         4096 Jan 15 14:01 ./target/source/two
   846272      4 -rw-r--r--   1 user     user          121 Jan 15 14:00 ./test.yml"><pre class="notranslate"><code class="notranslate">$ find . -ls
   852461      4 drwxr-xr-x   3 user     user         4096 Jan 15 14:00 .
   852463      4 drwxr-xr-x   4 user     user         4096 Jan 15 13:59 ./source
   860161      4 drwxr-xr-x   2 user     user         4096 Jan 15 13:59 ./source/one
   846271      4 -rw-r--r--   1 user     user            4 Jan 15 13:59 ./source/one/afile
   942425      4 drwxr-xr-x   2 user     user         4096 Jan 15 13:59 ./source/two
   846272      4 -rw-r--r--   1 user     user          121 Jan 15 14:00 ./test.yml
$ ansible-playbook test.yml
 [WARNING]: Unable to parse /etc/ansible/hosts as an inventory source

 [WARNING]: No inventory was parsed, only implicit localhost is available

 [WARNING]: Could not match supplied host pattern, ignoring: all

 [WARNING]: provided hosts list is empty, only localhost is available


PLAY [localhost] *****************************************************************************************

TASK [copy] **********************************************************************************************
changed: [localhost]

PLAY RECAP ***********************************************************************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=0   

$ find . -ls
   852461      4 drwxr-xr-x   4 user     user         4096 Jan 15 14:01 .
   852463      4 drwxr-xr-x   4 user     user         4096 Jan 15 13:59 ./source
   860161      4 drwxr-xr-x   2 user     user         4096 Jan 15 13:59 ./source/one
   846271      4 -rw-r--r--   1 user     user            4 Jan 15 13:59 ./source/one/afile
   942425      4 drwxr-xr-x   2 user     user         4096 Jan 15 13:59 ./source/two
   942429      4 drwxr-xr-x   3 user     user         4096 Jan 15 14:01 ./target
   942430      4 drwxr-xr-x   4 user     user         4096 Jan 15 14:01 ./target/source
   942431      4 drwxr-xr-x   2 user     user         4096 Jan 15 14:01 ./target/source/one
   942432      4 drwxr-xr-x   2 user     user         4096 Jan 15 14:01 ./target/source/two
   846272      4 -rw-r--r--   1 user     user          121 Jan 15 14:00 ./test.yml
</code></pre></div>

<p dir="auto">test.yml:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- hosts: localhost
  gather_facts: no
  become: no
  tasks:
    - copy:
        src: source/
        dest: target"><pre class="notranslate">- <span class="pl-ent">hosts</span>: <span class="pl-s">localhost</span>
  <span class="pl-ent">gather_facts</span>: <span class="pl-s">no</span>
  <span class="pl-ent">become</span>: <span class="pl-s">no</span>
  <span class="pl-ent">tasks</span>:
    - <span class="pl-ent">copy</span>:
        <span class="pl-ent">src</span>: <span class="pl-s">source/</span>
        <span class="pl-ent">dest</span>: <span class="pl-s">target</span></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>

<p dir="auto">The whole directory tree is copied.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>

<p dir="auto">No files are copied, only directories are created.</p>
<p dir="auto">This line<br>
<a href="https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/basic.py#L1365">https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/basic.py#L1365</a></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="os.chmod(dest, 0666 ^ umask)"><pre class="notranslate"><code class="notranslate">os.chmod(dest, 0666 ^ umask)
</code></pre></div>
<p dir="auto">should be</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="os.chmod(dest, 0666 &amp; ~umask)"><pre class="notranslate"><code class="notranslate">os.chmod(dest, 0666 &amp; ~umask)
</code></pre></div>
<p dir="auto">For a umask of 027 the current method gives 0641.<br>
The correct value would be 640</p>
<p dir="auto">It may not have been noticed before because for the most common umask (022) the two give the same value.</p>