我有一台安装了ansible的主机和一台连接到主机的远程机器 . 我能够从主机的终端内运行ansible playbook,并且能够ping并执行playbook .

[centos@test-1234 ~]$ ansible all -m ping
10.10.1.94 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

[centos@test-1234 ~]$ ansible-playbook varfiles_1.yml

PLAY [all] *********************************************************************

TASK [setup] *******************************************************************
ok: [10.10.1.94]

TASK [Test fact vs external variable comparison] *******************************
ok: [10.10.1.94 -> localhost]

PLAY RECAP *********************************************************************
10.10.1.94                 : ok=2    changed=0    unreachable=0    failed=0

但是,当我通过shell构建从jenkins运行相同的playbook时,我收到以下错误 .

script: ansible-playbook -u centos /home/centos/varfiles_1.yml

Building in workspace /var/lib/jenkins/workspace/test
[test] $ /bin/sh -xe /tmp/hudson4756676897950221446.sh
++ whoami
+ echo jenkins
jenkins
+ ansible-playbook -u centos /home/centos/varfiles_1.yml

PLAY [all] *********************************************************************

TASK [setup] *******************************************************************
fatal: [10.10.1.94]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Host key verification failed.\r\n", "unreachable": true}
 [WARNING]: Could not create retry file '/home/centos/varfiles_1.retry'.
[Errno 13] Permission denied: u'/home/centos/varfiles_1.retry'

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

构建步骤'执行shell'标记构建为失败完成:FAILURE

请求您的帮助进行调试 .

谢谢 .