install a custom .deb using states

3,232 views
Skip to first unread message

Adrien Saladin

unread,
Oct 22, 2012, 11:26:54 AM10/22/12
to salt-...@googlegroups.com
Hi, 

I'm very new to salt. I would like to install a custom mypackage.deb using states. The file sould be retrieved from the master for example with the built-in file server. 
I suppose it is a rather common task. Is there an example somewhere because I'm a little bit lost with how to assemble salt states ?


The lines below are just to show that I tried something. I expect it to be wrong in many aspects. 


Here is mypackage.sls:

mypackage:
   pkg:
     - installed
     - require:
         - file: /tmp/mypackage.deb
   cmd.run: 
     - names:
         - dpkg -i /tmp/mypackage.deb

/tmp/mypackage.deb:
   file.managed:
      - source: salt://mypackage.deb



When running salt '*' state.highstate I get this result:


minion1.mynetwork:
(in blue) ----------
    State: - cmd                                                                                                 
    Name:      dpkg -i /tmp/mypackage.deb
    Function:  run
        Result:    True
        Comment:   Command "dpkg -i /tmp/mypackage.deb" run
        Changes:   pid: 3963
                   retcode: 0                                                                                    
                   stderr:                                                                                       
                   stdout: (Reading database ... 131989 files and directories currently installed.)              
Preparing to replace mypackage 20121022-1 (using /tmp/mypackage.deb) ...                                                     
Unpacking replacement mypackage ...                                                                                    
Setting up mypackage (20121022-1) ... 
(/in blue)                                                                                 
                                                                                                                 
(in red) ----------
    State: - pkg                                                                                                 
    Name:      dpkg -i /tmp/mypackage.deb
    Function:  installed
        Result:    False
        Comment:   Package dpkg -i /tmp/mypackage.deb failed to install
        Changes:   
(/in red)


I'm using salt 0.10.1 since it is the one available with debian backports. 

Thanks

Ben Hosmer

unread,
Oct 22, 2012, 11:46:53 AM10/22/12
to salt-...@googlegroups.com
If you just run this:

dpkg -i /tmp/mypackage.deb

Do you get the same error?
--
Ben Hosmer

Brevard Tech - Brevard County Florida's Tech User Group

Ben Hosmer

unread,
Oct 22, 2012, 11:54:09 AM10/22/12
to salt-...@googlegroups.com
Or even this maybe:

mypackage:
   cmd.run: 
     - names: dpkg -i /tmp/mypackage.deb
     - require:
       - file: /tmp/mypackage.deb


/tmp/mypackage.deb:
   file.managed:
      - source: salt://mypackage.deb

Adrien Saladin

unread,
Oct 22, 2012, 11:55:35 AM10/22/12
to salt-...@googlegroups.com
On Monday, October 22, 2012 5:46:56 PM UTC+2, Ben Hosmer wrote:
If you just run this:

dpkg -i /tmp/mypackage.deb

Do you get the same error?

No, the .deb seems to install correctly:

# dpkg -i /tmp/mypackage.deb
(Reading database ... 131989 files and directories currently installed.)
Preparing to replace mypackage 20121022-1 (using /tmp/mypackage.deb) ...
Unpacking replacement mypackage ...
Setting up mypackage (20121022-1) ...
root@minion1:~#

Same result if installed with salt 'minion1' cmd.run "dpkg -i /tmp/mypackage.deb"

Sean Channel

unread,
Oct 22, 2012, 12:05:02 PM10/22/12
to salt-...@googlegroups.com, Ben Hosmer
Look at Ben's example here. You have to use cmd.run and not 'pkg' for
this case. the pkg module works only through the system's repositories
or on already installed packages.

_S.

Adrien Saladin

unread,
Oct 22, 2012, 12:07:06 PM10/22/12
to salt-...@googlegroups.com


On Monday, October 22, 2012 5:54:11 PM UTC+2, Ben Hosmer wrote:
Or even this maybe:

mypackage:
   cmd.run: 
     - names: dpkg -i /tmp/mypackage.deb
     - require:
       - file: /tmp/mypackage.deb


/tmp/mypackage.deb:
   file.managed:
      - source: salt://mypackage.deb


I have no more red text. But the package is installed with every state.highstate command. I would like to install it only when needed. 

Jack Kuan

unread,
Oct 22, 2012, 12:17:01 PM10/22/12
to salt-...@googlegroups.com
You can add a '– unless:' check so that the cmd.run will only be executed when the package is not already installed. See http://docs.saltstack.org/en/latest/ref/states/all/salt.states.cmd.html for an example with 'unless' and details.

This email and any files transmitted with it are confidential and intended solely for the recipient(s). If you are not the named addressee you should not disseminate, distribute, copy or alter this email. Any views or opinions presented in this email are solely those of the author and might not represent those of theScore, Inc. or any of its affiliates. Warning: Although theScore, Inc. has taken reasonable precautions to ensure no viruses are present in this email, the company cannot accept responsibility for any loss or damage arising from the use of this email or attachments.

Sean Channel

unread,
Oct 22, 2012, 12:35:25 PM10/22/12
to salt-...@googlegroups.com, Adrien Saladin
This is a good one, and there's been a commit in git that adds support
for doing this on one step. However, what you have right now is a
cmd.run that needs a requisite.

You could add an "unless" to the cmd.run that first checks to see if it
is already installed, for example:

mypackage:
cmd.run:
- names: dpkg -i /tmp/mypackage.deb
- unless: dpkg -s mypackage
- require:
- file: /tmp/mypackage.deb

_S.

Adrien Saladin

unread,
Oct 24, 2012, 4:11:50 AM10/24/12
to salt-...@googlegroups.com
Thank you very much, Ben, Sean and Jack. This works now. 

Cheers

Ben Hosmer

unread,
Oct 24, 2012, 7:44:03 AM10/24/12
to salt-...@googlegroups.com
You're welcome Adrien.

I wonder if the recent 10.4 adds this functionality?


On Wed, Oct 24, 2012 at 4:11 AM, Adrien Saladin <adrien....@gmail.com> wrote:
Thank you very much, Ben, Sean and Jack. This works now. 

Cheers




Reply all
Reply to author
Forward
0 new messages