I want to eval command via 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? Thanks in advance.
command
module expects an executable as parameter.
eval $(ssh-agent)
is an expression that a unix shell
can understand not ansible.
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
. Hope you've set ssh-agent
to some appropriate value somehow.
# 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.