Ansible (v1.6.5) 的同步模块提示输入密码(Enter passphrase for key)尽管我一开始就已经输入了运行剧本。
知道为什么吗?
我使用以下选项运行我的剧本:
-u myuser --ask-sudo-pass --private-key=/path/to/id_rsa
这是我的同步任务:
- name: synchronize source files in src location
sudo: yes
synchronize: src={{local_src}} dest={{project_dirs.src}} archive=yes delete=yes rsync_opts=["--compress"]
when: synchronize_src_files
使用 ssh-agent 更新
按照 Lekensteyn 的建议,我尝试使用 ssh-agent 。
我不再有提示,但任务失败。我缺少什么?
eval `ssh-agent -s`
ssh-add ~/.ssh/id_rsa
错误:
TASK: [rolebooks/project | synchronize source files in src location] **********
failed: [10.0.0.101] => {"cmd": "rsync --delay-updates -FF --compress --delete-after --archive --rsh 'ssh -i /home/vagrant/.ssh/id_rsa -o StrictHostKeyChecking=no' --rsync-path=\"sudo rsync\" [--compress] --out-format='<<CHANGED>>%i %n%L' /projects/webapp [email protected] /cdn-cgi/l/email-protection:/var/local/sites/project1/src", "failed": true, "rc": 12}
msg: sudo: no tty present and no askpass program specified
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(226) [sender=3.1.0]
The synchronize
命令(至少 Ansible 1.6.6)似乎忽略了 Ansible 打开的正常 SSH 控制套接字。您的任务可以扩展到以下内容:
{
"cmd": "rsync --delay-updates -FF --compress --archive
--rsh 'ssh -o StrictHostKeyChecking=no'
--out-format='<<CHANGED>>%i %n%L'
/home/me/src/ user@host:/dest/",
"failed": true,
"rc": 23
}
要获取这些详细信息,请使用以下命令运行您的剧本-v
选项。作为解决此问题的方法,您可以开始ssh-agent
并添加缓存您的 SSH 密钥ssh-add
。有关详细信息,请参阅他们的手册页。
额外的警告synchronize
module:
- 当运行时
sudo: yes
, ansible 将运行--rsh 'sudo ssh'
如果远程 sudo 配置需要密码和/或 TTY,这将会中断。解决办法:设置sudo: no
在你的任务定义中。
- 登录远程计算机的用户是您的 SSH 用户(
ansible_ssh_user
),而不是 sudo 用户。我还没有找到覆盖此用户的方法(除了未经测试的方法,该方法可以使用-o User
通过其他选项之一的选项(dest_port="22 -o User=your_user"
?)结合set_remote_user=yes
).
这取自我的任务文件:
- name: sync app files
sudo: no
synchronize: src={{app_srcdir}}/ dest={{appdir}}/
recursive=yes
rsync_opts=--exclude=.hg
# and of course Ubuntu 12.04 does not support --usermap..
#,--chown={{deployuser}}:www-data
# the above goes bad because ansible_ssh_user=user has no privileges
# local_action: command rsync -av --chown=:www-data
# {{app_srcdir}}
# {{deployuser}}@{{inventory_hostname}}:{{appdir}}/
# when: app_srcdir is defined
# The above still goes bad because {{inventory_hostname}} is not ssh host...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)