You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure DevOps Pipeline SSH连接失败问题求助

Azure DevOps Pipeline中SSH连接共享服务器失败问题求助

我在Azure DevOps Pipeline中运行Bash任务执行Ansible Playbook时,无法连接到共享服务器,已尝试两种方案均失败,具体情况如下:

方案1:使用SSH服务连接

已创建包含主机、用户、密钥信息的SSH服务连接,Pipeline任务代码如下:

- task: SSH@0
  displayName: 'Run shell command'
  inputs:
    sshEndpoint: 'ssendpoint'
    runOptions: inline
    inline:
        ls -lrt

执行错误信息:

2022-11-17T15:18:56.9717340Z ##[error]Failed to connect to remote machine. Verify the SSH service connection details. Error: Error: All configured authentication methods failed.

方案2:将SSH私钥存储在Pipeline库的安全文件中

Pipeline代码如下:

- task: DownloadSecureFile@1
  name: sshKey
  displayName: 'Download ssh key'
  inputs:
    secureFile: 'pipeline_key'
- task: Bash@3
  displayName: Install dependencies
  inputs:
     targetType: inline
     script: |
          python3 -m pip install --user ansible
- task: Bash@3
  displayName:  Prepare ansible environment
  inputs:
    targetType: inline
    script: |
         ls -lrt
         echo [webserver] > ./ci-scripts/inventory
         echo '$(HOST)' >> ./ci-scripts/inventory
         echo "" >> ./ci-scripts/inventory
         echo [webserver:vars] >> ./ci-scripts/inventory
         echo ansible_ssh_user='$(SSH_USER)' >> ./ci-scripts/inventory
         echo ansible_ssh_private_key_file=pipeline_key >> ./ci-scripts/inventory
         echo ansible_ssh_port='$(SSH_PORT)' >> ./ci-scripts/inventory
         echo ansible_ssh_common_args='-o StrictHostKeyChecking=no' >> ./ci-scripts/inventory
         ls -lrt ./ci-scripts/
         cat ./ci-scripts/inventory
         cd ./ci-scripts
         cp '$(sshKey.secureFilePath)' pipeline_key
         chmod 600 pipeline_key
         ansible -i inventory -m ping webserver

Inventory文件已成功创建,密钥文件在Pipeline中显示正常,但执行时出现以下错误:

2022-11-19T07:35:34.5472906Z ansible_ssh_common_args='-o StrictHostKeyChecking=no'
2022-11-19T07:35:35.9899965Z us.****.us | UNREACHABLE! => {
2022-11-19T07:35:35.9900751Z     "changed": false,
2022-11-19T07:35:35.9905399Z     "msg": "Failed to connect to the host via ssh: Warning: Permanently added '[us.*****.us]:****' (ED25519) to the list of known hosts.
u***-****@us.****.us: Permission denied (publickey).",
2022-11-19T07:35:35.9906494Z     "unreachable": true
2022-11-19T07:35:35.9906996Z }

补充信息

  • 本地笔记本终端使用同一密钥可正常SSH连接目标服务器
  • 已将所有Azure DevOps IP地址添加到服务器的允许列表中

恳请有相关经验的人士提供解决建议,谢谢!


内容的提问来源于stack exchange,提问作者Satyashil Deshpande

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 04:50:26