Ansible运行带有提示的安装命令



我正在尝试使用ansible来自动化我的工作站安装过程。我发现我无法安装末日emacs。它要么发送两个yes提示yes失败,要么甚至发送安装命令到doom失败。

- name: Install Doom Emacs
expect:
command: bash -c "~/.emacs.d/bin/doom install"
responses:
'Generate an envvar file? (see `doom help env` for details) (y or n)': 'y'
"Download and install all-the-icon's fonts? (y or n)": 'y'

尝试安装它只是一个小问题,而ansible无法解决吗?

编辑:这是与ansible核心2.12

我在这里看到了一个直接的问题:expect模块的默认timeout是30秒。在我的系统上,安装(通过运行time ~/.emacs.d/bin/doom install计时(大约需要2分30秒。即使您期望/发送配置是正确的,您的任务也会在安装完成之前超时。试试类似的东西:

- name: Install Doom Emacs
expect:
command: bash -c "~/.emacs.d/bin/doom install"
timeout: 300
responses:
'Generate an envvar file? (see `doom help env` for details) (y or n)': 'y'
"Download and install all-the-icon's fonts? (y or n)": 'y'

其次,我很难让底层的pexpect模块成功地匹配Generate an envvar file? (seedoom help envfor details) (y or n)。与其在这个问题上花费更多的时间,我们只需要匹配一个子字符串,就可以得到:

- name: Install Doom Emacs
expect:
command: bash -c "~/.emacs.d/bin/doom install"
timeout: 300
responses:
"Generate an envvar file?": "yn"
"Download and install": "yn"

第三(他补充道,在答案已经被接受之后(,你不是";按下回车键";发送回复后。也就是说,你有:

responses:
'Generate an envvar file? (see `doom help env` for details) (y or n)': 'y'

这就像键入y,然后再也不按回车键,所以安装程序会在提示下永远等待。我已经修改了两个响应,以便在y之后发送一个换行符(n(。

以上任务对我来说运行成功。


这里的根本问题是doom没有非交互式安装模式,这使得使用任何工具都很难实现自动化。有一个问题需要添加,看起来作者已经接受了这一点,正在进行重写,但重写问题已经公开了近两年,所以不清楚在不久的将来会有什么变化。

最新更新