Question

I use saltstack to deploy my servers. I want to install all "tomcat7" pkgs on one server. So I write a sls file like this:

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

But in the end, it receives an error:

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

But in fact, the server has install all ^tomcat7.* packages sucessfully.

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

How to solve this problem? Am I need to write all ^tomcat7.* pkgs one by one?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top