我如何让cmd.run在salt-stack中回答提示?

我有一个正在执行state.sls的盐脚本,如下所示:

 salt '*' state.sls foo.bar 

在我的脚本中,我有这样的:

 foo-bar: cmd.run: - php foo.php bar --delete - cwd: /srv/foo 

--delete标志将导致脚本首先截断数据库。 我的问题是,它提出一个问题,并期待一个input。

 root@host:/srv/foo# php foo.php bar --delete This is going to remove all data in the database. Are you sure? [y/n]: 

因为盐不知道如何回答,它会超时,中止,做我不打算的事情。

cmd.run上的盐文档没有说这样做,我不知道什么谷歌。 我知道在一个Perl实现中,我会使用Expect来执行此操作。

我如何告诉盐,请用y回答?

在最近的salt版本中,你可以给cmd.run提供“stdin”

 A string of standard input can be specified for the command to be run using the ``stdin`` parameter. This can be useful in cases where sensitive information must be read from standard input.: salt '*' cmd.run "grep f" stdin='one\ntwo\nthree\nfour\nfive\n' 

你可以创build一个脚本来执行它,并通过cmd.script运行它,甚至创build一个自定义的python模块。