1

yaml所以我在我的ansible项目中有这块。

- name: common | register vim as a type of editor for update-alternatives
  command: update-alternatives --install "/usr/bin/editor" "editor" $(which vim) 100
  sudo: yes

我想要做的是注册为一种editor,将其设置priority为 100。

因为我可以在终端中执行此行,但是,我无法将其写入ansible,这是错误:

标准错误:更新替代:优先级必须是整数

无论如何我可以将“100”转换为整数而不是字符串?

4

2 回答 2

2

来自ansible的来源:

如果你想通过 shell 运行命令(比如你正在使用 <、>、| 等),你实际上需要 shell 模块。命令模块更安全,因为它不受用户环境的影响。

在这种情况下,请改用shell模块。

如果你还想要更安全的command

将任何shell 命令表示为其完整路径(因为未加载任何环境)。

于 2013-10-09T09:51:27.693 回答
1

原来我不能通过$(which vim)这里。

如果我将行更改为:

command: update-alternatives --install "/usr/bin/editor" "editor" "/usr/bin/vim" 100

问题解决了。

于 2013-10-09T09:07:44.737 回答