更新时间:2023-11-11 22:22:10
source
是一个内部 shell 命令(参见例如 Bash 内置命令),而不是可以运行的外部程序.您的系统中没有名为 source
的可执行文件,这就是您收到 No such file or directory
错误的原因.
source
is an internal shell command (see for example Bash Builtin Commands), not an external program which you can run. There is no executable named source
in your system and that's why you get No such file or directory
error.
代替 command
模块使用 shell
将在 shell 中执行 source
命令.
Instead of the command
module use shell
which will execute the source
command inside a shell.
在 with_items
循环中,Ansible 将运行 shell 两次,并且两个进程将相互独立.在一个中设置的变量不会被另一个看到.
In a with_items
loop Ansible will run the shell twice and both processes will be independent of each other. Variables set in one will not be seen by the other.
您应该在一个 shell 进程中运行这两个命令,例如:
You should run the two commands in one shell process, for example with:
- name: Install node {{ nvm.node_version }}
shell: "source /home/centos/.nvm/nvm.sh && nvm install {{ nvm.node_version }}"
tags: nvm
在 git
任务中使用 {{ ansible_env.HOME }}
而不是 ~
.任何一个都可以在这里工作,但波浪号扩展是 shell 的功能,您正在为 Ansible 编写代码.
Use {{ ansible_env.HOME }}
instead of ~
in the git
task. Either one will work here, but tilde expansion is the functionality of shell and you are writing code for Ansible.