salt icon indicating copy to clipboard operation
salt copied to clipboard

require pkg fails when installing package with pkgs

Open rca opened this issue 13 years ago • 6 comments

Hello,

I setup a salt state to install multiple packages using:

packages:
  pkg.installed:
    - pkgs:
      - postgresql-client-9.2
      - postgresql-9.2
  [...]

and subsequently wanted to make sure the package was installed before starting the service:

postgresql:
  service:
    - running
    - require:
      pkg: postgresql-9.2

This ends up in an error:

    State: - service
    Name:      postgresql
    Function:  running
        Result:    False
        Comment:   The following requisites were not found:
                   require: {'pkg': 'postgresql-9.2'}

        Changes:   

It feels like pkg within a require clause should be aware of packages installed with pkgs. I was able to get around the issue by using require_in under my packages section.

I put together a gist that uses require under the service to illustrate the issue and another gist that gets around the problem using require_in.

Thanks!

rca avatar Feb 11 '13 20:02 rca

Try this instead. https://gist.github.com/thekuffs/4757448

thekuffs avatar Feb 11 '13 20:02 thekuffs

@thekuffs, thanks! I knew it was something minor. From our IRC chat:

kuffs: berto-: you can only use ids for requisites. so the top-level key for any given individual resource

rca avatar Feb 11 '13 20:02 rca

If you change the YAML then it will work

packages:
  pkg.installed:
    - pkgs:
      - postgresql-client-9.2
      - postgresql-9.2

postgresql:
  service:
    - running
    - require:
      - pkg: postgresql-9.2

grep4linux avatar Aug 14 '15 15:08 grep4linux

No, it won't. You'd have to require pkg: packages.

brevilo avatar May 12 '16 14:05 brevilo

I recently ran into this issue in a very similar scenario. I'm not sure I follow this:

kuffs: berto-: you can only use ids for requisites. so the top-level key for any given individual resource

The docs say:

Requisites need two pieces of information for matching: The state module name – e.g. pkg –, and the identifier – e.g. vim –, which can be either the ID (the first line in the stanza) or the - name parameter.

But I guess internally, pkg.installed with a pkgs list doesn't resolve the same way as explicitly providing a name parameter? I guess my heartache is that it's not obvious anywhere in the docs that this is an issue, and that by installing a bunch of system packages this way, you can no longer use require and ensure that a specific package is installed. Instead, if you want to be able to do that, you have to break out each one individually.

Note: there was a suggestion to depend on the whole list. I don't want to do that here. I want to write a state that is explicit and correct and keep me honest if I remove package from the list but want this state. My hope was that pkg: foo was checking to see if foo was in the package list, not if there is a state somewhere that uses pkg and has a name of foo. To be fair, the requisites are to create relationships between states, I just wish this and other gotchas could be captured somewhere. It seems important for designing good states.

jszakmeister avatar Dec 23 '16 08:12 jszakmeister

If you want, you can use names instead of pkgs and then depend on a single package. See the warning at [1]:

https://docs.saltstack.com/en/latest/ref/states/all/salt.states.pkg.html#salt.states.pkg.installed

Unlike pkgs, the names parameter cannot specify a version. In addition, it makes a separate call to the package management frontend to install each package, whereas pkgs makes just a single call. It is therefore recommended to use pkgs instead of names to install multiple packages, both for the additional features and the performance improvement that it brings.

wdoekes avatar Jun 12 '17 08:06 wdoekes