Why Do I Get "sftp transfer mechanism failed" Warning on Ansible Engine?

Solution Verified - Updated -

Environment

  • Ansible Engine

Issue

  • When I execute a playbook, all tasks have been succeeded but I see the following warning:

    [WARNING]: sftp transfer mechanism failed on [192.0.2.1]. Use ANSIBLE_DEBUG=1 to see detailed information.
    

Resolution

  • Please check and modify /etc/ssh/sshd_config on your managed nodes to enable sftp on subsystem settings for sshd.

    # cat /etc/ssh/sshd_config | grep Subsystem
    Subsystem       sftp    /usr/libexec/openssh/sftp-server
    

Root Cause

  • When you specify transfer_method = smart which is default method in ansible.cfg, it will try to use sftp as first protocol to transfer AnsiballZ package. If it was disabled on sshd on managed node, it will show the WARNINGS and fallback to scp instead of sftp.

  • Here is the default configuration on ansible.cfg.

    [ssh_connection]
    # Control the mechanism for transferring files (old)
    #   * smart = try sftp and then try scp [default]
    #   * True = use scp only
    #   * False = use sftp only
    #scp_if_ssh = smart
    
    # Control the mechanism for transferring files (new)
    # If set, this will override the scp_if_ssh option
    #   * sftp  = use sftp to transfer files
    #   * scp   = use scp to transfer files
    #   * piped = use 'dd' over SSH to transfer files
    #   * smart = try sftp, scp, and piped, in that order [default]
    #transfer_method = smart
    

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments