3

我使用 saltstack 来部署我的服务器。我想在一台服务器上安装所有“tomcat7”pkg。所以我写了一个这样的sls文件:

 ^tomcat7.*:
  pkg:
    - installed
  - require:
    - pkg: openjdk-7-jdk 

但最后,它收到一个错误:

----------
State: - pkg
Name:      ^tomcat7.*
Function:  installed
    Result:    False
    Comment:   Package ^tomcat7.* failed to install
    Changes:  

但事实上,服务器已经成功安装了所有的 ^tomcat7.* 包。

root@vagrant-ubuntu-raring-64:~# dpkg -l tomcat7*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                                  Version                         Architecture                    Description
+++-=====================================================-===============================-===============================-===============================================================================================================
ii  tomcat7                                               7.0.35-1~exp2ubuntu1.1          all                             Servlet and JSP engine
ii  tomcat7-admin                                         7.0.35-1~exp2ubuntu1.1          all                             Servlet and JSP engine -- admin web applications
ii  tomcat7-common                                        7.0.35-1~exp2ubuntu1.1          all                             Servlet and JSP engine -- common files
ii  tomcat7-docs                                          7.0.35-1~exp2ubuntu1.1          all                             Servlet and JSP engine -- documentation
ii  tomcat7-examples                                      7.0.35-1~exp2ubuntu1.1          all                             Servlet and JSP engine -- example web applications
ii  tomcat7-user                                          7.0.35-1~exp2ubuntu1.1          all                             Servlet and JSP engine -- tools to create user instances

如何解决这个问题呢?我需要一一写所有 ^tomcat7.* pkgs 吗?

4

1 回答 1

4

So the problem here is that the pkg.installed state is checking the installed packages list for an exact match of ^tomcat7.*, without using regex. It finds that that package is not present, so it attempts to install it. The attempt works because the packaging system obviously does support regex. pkg.installed then checks the installed package list for ^tomcat7.* again (without regex), and finds it is still missing, so it reports an error.

The solution here could be to add another argument to pkg.installed which switches on regex matching. However, this makes the state less deterministic, because we will just search through the list of packages for a match on the regex, and will not verify that all the packages with that regex are installed. This could backfire if, for example, just the tomcat7 package had been installed previously. pkg.installed would see that there was a match, and not install the rest of the packages.

You'd be much better off to use the pkgs argument to give a list of all the exact packages you need. It is much more deterministic this way, and you know they will all be installed, even if one or more had been installed previously.

于 2013-08-21T17:26:40.343 回答