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

时间:2015-12-04 11:42:56

标签: ansible ansible-playbook

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

"$(which nodejs)"

我发现部分fs.rename(new Path("a"), new Path("b"))不会插入到字符串中,而是采用字面的方式 - 因此,会创建格式错误的符号链接。

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

1 个答案:

答案 0 :(得分:3)

那么,

我可能会急于先问,而不是自己寻找解决方案。这是一个解决方案:

---
- 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
相关问题