<p>The reason for the failure is that the server in question, unlike all the others, had sftp disabled. 
Why the error messages are what they are, I don't know (why the errant <code>scp transfer mechanism failed</code>?), but I don't have time right now to investigate with the debug option enabled.</p>

<p>But that was the issue, and adding <code>scp_if_ssh=True</code> to the <code>[ssh_connection]</code> section of my <code>ansible.cfg</code> solved the issue:</p>

<pre><code>[ssh_connection]                                                                   
scp_if_ssh=True 
</code></pre>

CC BY-SA 3.0
2017-07-17T20:04:26.000Z
2017-07-17T20:04:26.000Z
fildred13
<p>I have an ansible playbook which can be simplified to this:</p>

<pre><code>- name: Provision server                  
  hosts: all_hosts                                                           
  become: yes                                                                                                                                     
  roles:                                                                                                                                                    
    - { role: foo }
</code></pre>

<p>With the following in <code>ansible.cfg</code>, since it may be relevant:</p>

<pre><code>[defaults]                                                                         
allow_world_readable_tmpfiles = True                                               
host_key_checking = False                                                          
log_path=./ansible.log                                                             
remote_user = ubuntu   
</code></pre>

<p>That playbook successsfully configures 10 servers, but one of the servers fails with:</p>

<pre><code>[WARNING]: sftp transfer mechanism failed on [xx.xx.xxx.xxx]. Use
ANSIBLE_DEBUG=1 to see detailed information
 [WARNING]: scp transfer mechanism failed on [xx.xx.xxx.xxx]. Use
ANSIBLE_DEBUG=1 to see detailed information
fatal: [host_1]: FAILED! =&gt; {"failed": true, "msg": "failed to transfer file to /home/ubuntu/.ansible/tmp/ansible-tmp-1500318083.01-204857088854554/stat.py:\n\nscp: /home/ubuntu/.ansible/tmp/ansible-tmp-1500318083.01-204857088854554/stat.py: Permission denied\n"}
</code></pre>

<p>So I ssh'd to the problematic server and a "healthy" server, and <code>ls -al</code> the contents of the latest temp folder for each. The healthy server had files with permissions of <code>rwx --- ---</code>. The unhealthy server had this:</p>

<pre><code>---x------ 1 ubuntu ubuntu 58378 Jul 17 14:09 file.py
---x------ 1 ubuntu ubuntu 56779 Jul 17 14:09 stat.py
</code></pre>

<p>Why would those files get those permissions? I assume that is the problem, because then scp tries to write to them, but it cannot. That doesn't totally make sense with the error message, though, which seems to be suggesting that the <code>scp</code> fails.</p>

<p>I'm trying to figure out what debug steps to take, and if anyone can think of other places I can look in order to provide more information, I'm all ears.</p>

CC BY-SA 3.0
2017-07-17T19:52:20.633Z
Does using ANSIBLE_DEBUG=1 tell you anything useful?
Dave W. Smith
CC BY-SA 3.0
2017-07-17T20:02:47.523Z
@Dave I was in the process of getting my environment ready to run with that set, when I stumbled upon `scp_if_ssh` configuration setting in the ansible docs. I tried it, and it worked. See the answer for details if you're interested.
fildred13
<ansible><linux><permissions>
Ansible tmp files created with odd permissions
fildred13
# Ansible tmp files created with odd permissions

(Asked by: username_0 on 2017-07-17)

I have an ansible playbook which can be simplified to this:
- name: Provision server                  
  hosts: all_hosts                                                           
  become: yes                                                                                                                                     
  roles:                                                                                                                                                    
    - { role: foo }

With the following in ansible.cfg, since it may be relevant:
[defaults]                                                                         
allow_world_readable_tmpfiles = True                                               
host_key_checking = False                                                          
log_path=./ansible.log                                                             
remote_user = ubuntu   

That playbook successsfully configures 10 servers, but one of the servers fails with:
[WARNING]: sftp transfer mechanism failed on [xx.xx.xxx.xxx]. Use
ANSIBLE_DEBUG=1 to see detailed information
 [WARNING]: scp transfer mechanism failed on [xx.xx.xxx.xxx]. Use
ANSIBLE_DEBUG=1 to see detailed information
fatal: [host_1]: FAILED! => {"failed": true, "msg": "failed to transfer file to /home/ubuntu/.ansible/tmp/ansible-tmp-1500318083.01-204857088854554/stat.py:\n\nscp: /home/ubuntu/.ansible/tmp/ansible-tmp-1500318083.01-204857088854554/stat.py: Permission denied\n"}

So I ssh'd to the problematic server and a "healthy" server, and ls -al the contents of the latest temp folder for each. The healthy server had files with permissions of rwx --- ---. The unhealthy server had this:
---x------ 1 ubuntu ubuntu 58378 Jul 17 14:09 file.py
---x------ 1 ubuntu ubuntu 56779 Jul 17 14:09 stat.py

Why would those files get those permissions? I assume that is the problem, because then scp tries to write to them, but it cannot. That doesn't totally make sense with the error message, though, which seems to be suggesting that the scp fails.
I'm trying to figure out what debug steps to take, and if anyone can think of other places I can look in order to provide more information, I'm all ears.

**Tags:** ansible, linux, permissions

> **Comments:**
> **username_1**: Does using ANSIBLE_DEBUG=1 tell you anything useful?  
> **username_0**: @Dave I was in the process of getting my environment ready to run with that set, when I stumbled upon `scp_if_ssh` configuration setting in the ansible docs. I tried it, and it worked. See the answer for details if you're interested.  

---

## 1 answers

### Answer by username_0 on 2017-07-17. Score: 3

The reason for the failure is that the server in question, unlike all the others, had sftp disabled. 
Why the error messages are what they are, I don't know (why the errant scp transfer mechanism failed?), but I don't have time right now to investigate with the debug option enabled.
But that was the issue, and adding scp_if_ssh=True to the [ssh_connection] section of my ansible.cfg solved the issue:
[ssh_connection]                                                                   
scp_if_ssh=True


---

