Search code examples
githubsalt-project

Package build with Saltstack


I'm attempting to get a specific package pulled from Github and installed with Salt (in a masterless configuration) when provisioning a machine. So far, I've managed to do so like this:

{% set pkg = {
'Ubuntu': 'https://github.com/some-package/releases/download/v1/some-package-v1-unknown-linux-gnu.deb',
}.get(grains.os) %}

curl -O -L {{ pkg }}:
    cmd.run

dpkg -i some-pakage-v1-unknown-linux-gnu.deb:
    cmd.run

Now, Salt does have a module that seems to do this exact thing, it's called pkgbuild.built. I tried using it but without much success. This is what I've right at the moment:

some-pakage-v1:
    pkgbuild.built:
        - runas: root
        - results:
        - some-package-v1-unknown-linux-gnu.deb
        - dest_dir: /tmp/pkg
        - spec: salt://pkg/salt/spec/some-package.spec
        - tgt: ubuntu-18.04.1-x86_64
        - sources:
            - {{ pkg }}

And I'm getting this error:

      ID: some-pakage-v1
Function: pkgbuild.built
  Result: False
 Comment: An exception occurred in this state: Traceback (most recent call last):
            File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1913, in call
              **cdata['kwargs'])
            File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1898, in wrapper
              return f(*args, **kwargs)
            File "/usr/lib/python2.7/dist-packages/salt/states/pkgbuild.py", line 207, in built
              ret['changes'] = __salt__[func](
            File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1155, in __getitem__
              func = super(LazyLoader, self).__getitem__(item)
            File "/usr/lib/python2.7/dist-packages/salt/utils/lazy.py", line 104, in __getitem__
              raise KeyError(key)
          KeyError: 'pkgbuild.build'
 Started: 18:29:57.051892
Duration: 9.644 ms
 Changes:  

Solution

  • Could it be that you made a mistake in the indentation?

    According to the documentation, I would expect this:

    some-pakage-v1:
        pkgbuild.built:
            - runas: root
            - results:
                - some-package-v1-unknown-linux-gnu.deb
            - dest_dir: /tmp/pkg
            - spec: salt://pkg/salt/spec/some-package.spec
            - tgt: ubuntu-18.04.1-x86_64
            - sources:
                - {{ pkg }}
    

    The line after results has to be indented

    Still, in your case, if you want to install the .deb file, why not the pkg.installed rules?

    some-package-v1:
      pkg.installed:
        - sources: 
            - some-package-v1: https://github.com/some-package/releases/download/v1/some-package-v1-unknown-linux-gnu.deb