繁体   English   中英

eval命令如何在ansible playbook中工作

[英]How can eval command work in ansible playbook

我想通过ansible playbook来评估命令。 这是剧本。

 - name: enable ssh-agent
   command: eval $(ssh-agent)

我试过这本剧本。

$ ansible-playbook -i hosts site.yml

但我得到了这个错误。

failed: [host] => {"cmd": "eval", "failed": true, "rc": 2}
msg: [Errno 2] No such file or directory

FATAL: all hosts have already failed -- aborting

eval命令如何在ansible playbook中工作? 提前致谢。

command模块期望可执行文件作为参数。

eval $(ssh-agent)是一个unix shell可以理解为不可回复的表达式。

正如tedder所说,我不明白你为什么要设置ssh-agent,但如果你这样做,我建议你试试shell模块而不是command 希望你以某种方式将ssh-agent设置为适当的值。

 # Just for debugging.
 - name: enable ssh-agent
   shell: echo "ssh-agent = $(ssh-agent)"
 - name: enable ssh-agent
   shell: eval $(ssh-agent)

在这种情况下,ansible会将整个字符串传递给shell,shell会对其进行评估。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM