Question

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
Was it helpful?

Solution 2

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.

OTHER TIPS

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.

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