14

I'm getting my feet wet with SaltStack. I've made my first state (a Vim installer with a static configuration) and I'm working on my second one.

Unfortunately, there isn't an Ubuntu package for the application I'd like my state to install. I will have to build the application myself. Is there a "best practice" for doing "configure-make-install" type installations with Salt? Or should I just use cmd?

In particular, if I was doing it by hand, I would do something along the lines of:

wget -c http://example.com/foo-3.4.3.tar.gz
tar xzf foo-3.4.3.tar.gz
cd foo-3.4.3
./configure --prefix=$PREFIX && make && make install
nomen
  • 3,626
  • 2
  • 23
  • 40

2 Answers2

23

There are state modules to abstract the first two lines, if you wish.

But you could also just run the commands on the target minion(s).

install-foo:
  cmd.run:
    - name: |
        cd /tmp
        wget -c http://example.com/foo-3.4.3.tar.gz
        tar xzf foo-3.4.3.tar.gz
        cd foo-3.4.3
        ./configure --prefix=/usr/local
        make
        make install
    - cwd: /tmp
    - shell: /bin/bash
    - timeout: 300
    - unless: test -x /usr/local/bin/foo

Just make sure to include an unless argument to make the script idempotent.

Alternatively, distribute a bash script to the minion and execute. See: How can I execute multiple commands using Salt Stack?

As for best practice? I would recommend using fpm to create a .deb or .rpm package and install that. At the very least, copy that tarball to the salt master and don't rely on external resources to be there three years from now.

Community
  • 1
  • 1
Dan Garthwaite
  • 3,436
  • 4
  • 22
  • 32
  • Good point about external resources. I'll probably set up an nginx server on the master to mirror the resources I need. Thanks for your suggestions! – nomen Feb 15 '14 at 03:23
  • 2
    Your unless clause won't work as you expect. It should be a plain string entry rather than a list. It currently always returns true. – Tavis Rudd May 24 '14 at 05:17
  • 2
    +1 on packing the binary with `fpm`, especially if you're running in EC2 or another cloud. If you're using long-running instances, it doesn't much matter if you spend an extra minute or two over the course of your first salt run, but if you're running short-lived instances in ec2, you definitely don't want to pay for that compile time over and over. – Joe Block Jan 25 '15 at 23:07
11

Let's assume foo-3.4.3.tar.gz is checked into GitHub. Here is an approach that you might pursue in your state file:

git:
  pkg.installed

https://github.com/nomen/foo.git:
  git.latest:
    - rev: master
    - target: /tmp/foo
    - user: nomen
    - require:
      - pkg: git

foo_deployed:
  cmd.run:
    - cwd: /tmp/foo
    - user: nomen
    - name: |
        ./configure --prefix=/usr/local
        make
        make install
    - require:
      - git: https://github.com/nomen/foo.git

Your configuration prefix location could be passed as a salt pillar. If the build process is more complicated, you may consider writing a custom state.

davidjb
  • 8,247
  • 3
  • 32
  • 42
Jeff Bauer
  • 13,890
  • 9
  • 51
  • 73
  • I have a similar problem, the `make install` requires a binary (golang) that was previously installed with a formula. The problem is that PATH is not reloaded and the make cannot find the new installed binary. Can this be solved using a state or formula? – BG Adrian Nov 21 '18 at 20:05