当我手动[一个接一个]手动运行以下命令时,ssh-agent转发适用于远程主机:
var percent_pass; // declaration of the variable placed outside of any function => global variable
$(document).ready(function(){
jQuery(function(){
percent_pass = 0; // just assign a value.
});
});
$(window).load(function() {
doughnutWidget.options = {
container: $('#container'),
width: 100,
height: 100,
class: 'myClass',
cutout: 50
};
doughnutWidget.render(data());
setInterval(init, 2000);
});
function init() {
doughnutWidget.render(data());
}
function data() {
var data = {
pending: {
val: Math.round(percent_pass),
color: '#57B4F2',
},
delivered: {
val: Math.round(percent_pass),
color: '#6DED5C'
},
delayed: {
val: Math.round(percent_pass),
color: '#E63329',
}
};
return data;
}
但是,当我将它们捆绑在一个shell脚本中并作为Ansible游戏运行时,ssh转发不起作用。像这样:
eval `ssh-agent -s`
ssh-add <>.pem
它返回同样的错误:
changed: [localhost] => {
"changed": true,
"cmd": "sh test.sh",
"delta": "0:00:00.008763",
"end": "2017-03-29 12:10:12.337557",
"invocation": {
"module_args": {
"_raw_params": "sh test.sh",
"_uses_shell": true,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"warn": true
},
"module_name": "command"
},
"rc": 0,
"start": "2017-03-29 12:10:12.328794",
"stderr": "Identity added: <>.pem (<>.pem)",
"stdout": "Agent pid <>",
"stdout_lines": [
"Agent pid <>"
],
"warnings": []
}
我的ansible.cfg看起来像这样:
fatal: [<>]: UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: Permission denied (publickey).\r\n",
"unreachable": true
}
那么,如何在不在主机中手动输入ssh-add命令的情况下启用ssh-agent转发(可能通过ansible本身?)?
答案 0 :(得分:1)
这就是你要找的东西 http://docs.ansible.com/ansible/intro_configuration.html#private-key-file
在路径中添加pem文件以避免不必要的并发症。