ubuntu 14.04.3 LTS ansible version:2.1.0,远程服务器上的sshport是44022
我使用adhoc方式运行同步模块作为sudo用户[nopasswd is not enabled
]来同步本地和远程目录(推送)
下面是主机文件/ etc / ansible / hosts
[webdb]
10.153.99.132
10.153.99.52
[webdb:vars]
ansible_ssh_user=ctuser
ansible_ssh_private_key_file=/root/.ssh/id_rsa
ansible_port=44022
以下是使用的命令:
ansible webdb -s -K -m synchronize -a "src=/tmp/muhan
dest=/store" -u ctuser
和(使用了dest_port)
ansible webdb -s -K -m synchronize -a "dest_port=44022
src=/tmp/muhan dest=/store" -u ctuser
两个命令输出以下错误: -
10.153.99.52 | FAILED! => {
"changed": false,
"cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh 'ssh -i /root/.ssh/id_rsa -S none -o StrictHostKeyChecking=no -o Port=44022' --rsync-path=\"sudo rsync\" --out-format='<<CHANGED>>%i %n%L' \"/tmp/muhan\" \"ctuser@10.153.99.52:/store\"",
"failed": true,
"msg": "sudo: unable to resolve host c2.example.com\nsudo: no tty present and no askpass program specified\nrsync: connection unexpectedly closed (0 bytes received so far) [sender]\nrsync error: error in rsync protocol data stream (code 12) at io.c(226) [sender=3.1.0]\n",
"rc": 12
}
10.153.99.132 | FAILED! => {
"changed": false,
"cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh 'ssh -i /root/.ssh/id_rsa -S none -o StrictHostKeyChecking=no -o Port=44022' --rsync-path=\"sudo rsync\" --out-format='<<CHANGED>>%i %n%L' \"/tmp/muhan\" \"ctuser@10.153.99.132:/store\"",
"failed": true,
"msg": "sudo: unable to resolve host c1.example.com\nsudo: no tty present and no askpass program specified\nrsync: connection unexpectedly closed (0 bytes received so far) [sender]\nrsync error: error in rsync protocol data stream (code 12) at io.c(226) [sender=3.1.0]\n",
"rc": 12
}
答案 0 :(得分:0)
您可以从多个角度解决这个问题:
禁用sudo tty要求:sed -i 's/Defaults requiretty/Defaults !requiretty/g' /etc/sudoers
(这是在您使用Ansible的所有节点上)
将ansible.cfg更改为ssh http://docs.ansible.com/ansible/intro_configuration.html#ssh-args的tty标志(这仅在您执行Ansible的节点上)
您需要的确切开关:
ssh_args = -tt