[英]How can eval command work in ansible playbook
I want to eval command via ansible playbook. 我想通过ansible playbook来评估命令。 Here's playbook. 这是剧本。
- name: enable ssh-agent
command: eval $(ssh-agent)
I tried this playbook. 我试过这本剧本。
$ ansible-playbook -i hosts site.yml
But I got this error. 但我得到了这个错误。
failed: [host] => {"cmd": "eval", "failed": true, "rc": 2}
msg: [Errno 2] No such file or directory
FATAL: all hosts have already failed -- aborting
How eval command work in ansible playbook? eval命令如何在ansible playbook中工作? Thanks in advance. 提前致谢。
command
module expects an executable as parameter. command
模块期望可执行文件作为参数。
eval $(ssh-agent)
is an expression that a unix shell
can understand not ansible. eval $(ssh-agent)
是一个unix shell
可以理解为不可回复的表达式。
as tedder said I don't see why you want to setup ssh-agent, but if you do I recommend you give the shell
module a try instead of command
. 正如tedder所说,我不明白你为什么要设置ssh-agent,但如果你这样做,我建议你试试shell
模块而不是command
。 Hope you've set ssh-agent
to some appropriate value somehow. 希望你以某种方式将ssh-agent
设置为适当的值。
# Just for debugging.
- name: enable ssh-agent
shell: echo "ssh-agent = $(ssh-agent)"
- name: enable ssh-agent
shell: eval $(ssh-agent)
In this case ansible would pass the whole string to shell and shell would evaluate it. 在这种情况下,ansible会将整个字符串传递给shell,shell会对其进行评估。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.