在Ansible运行的shell命令中插入变量

在Ansible运行的shell命令中插入变量,ansible,ansible-playbook,Ansible,Ansible Playbook,我想运行与此类似的Ansible任务: --- - name: symlink the nodejs executable to node command: ln -sf "$(which nodejs)" /usr/bin/node sudo: True 我发现,“$(哪个节点)”部分不会被插入到字符串中,而是以文字形式执行-因此,创建了一个格式错误的符号链接 如何使用Ansible命令模块将此部分插入到正确的字符串中?好 我可能是迫不及待地想先问,而不是自己去寻找解决办法。这里有一

我想运行与此类似的Ansible任务:

---
- name: symlink the nodejs executable to node
  command: ln -sf "$(which nodejs)" /usr/bin/node
  sudo: True
我发现,
“$(哪个节点)”
部分不会被插入到字符串中,而是以文字形式执行-因此,创建了一个格式错误的符号链接

如何使用Ansible命令模块将此部分插入到正确的字符串中?

我可能是迫不及待地想先问,而不是自己去寻找解决办法。这里有一个解决方案:

---
- name: Find path to nodejs
  command: which nodejs
  register: nodejs_path

- name: symlink the nodejs executable to node
  command: "ln -sf {{ item }} /usr/bin/node"
  sudo: True
  with_items: nodejs_path.stdout