Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Chef infra 以其他用户身份运行Chef guard block_Chef Infra - Fatal编程技术网

Chef infra 以其他用户身份运行Chef guard block

Chef infra 以其他用户身份运行Chef guard block,chef-infra,Chef Infra,我想要一个Chef guard块,并且我想要以特定用户的身份运行该块 我知道如何以用户身份在guard中运行shell命令,因为文档中已经介绍了这一点: not_if 'grep adam /etc/passwd', :user => 'adam' 我想改用一个保护块,这样我可以做一些更复杂的操作,并且我想以postgres用户的身份运行代码。例如: only_if do c = PGconn.connect(user: 'postgres', dbname: 'postgres')

我想要一个Chef guard块,并且我想要以特定用户的身份运行该块

我知道如何以用户身份在guard中运行shell命令,因为文档中已经介绍了这一点:

not_if 'grep adam /etc/passwd', :user => 'adam'
我想改用一个保护块,这样我可以做一些更复杂的操作,并且我想以postgres用户的身份运行代码。例如:

only_if do
  c = PGconn.connect(user: 'postgres', dbname: 'postgres')
  # do some other stuff with the postgres connection
end

如何在这里分配
用户
或其他属性?

代码块本身并不是以用户身份运行的,它们只是由Ruby作为用户运行。在这种情况下,您可能希望退出到
psql
,并根据子流程的正常情况更改用户