Skip to content

Instantly share code, notes, and snippets.

@alexhayes
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexhayes/bbffb9f435984fba11a0 to your computer and use it in GitHub Desktop.
Save alexhayes/bbffb9f435984fba11a0 to your computer and use it in GitHub Desktop.
Require using sls fails

I'm attempting to have a state depend on another state (state 'chaining' as outlined here)

In my example I have an include for the 'php' formula.

On line 14 of init.sls you can see - sls: php which is supposed to ensure that state install-pear depends on the php state which is derived from php.init.sls (included below for clarity).

When I execute salt foo state.highstate test=True I receive the following:

foo:
----------
          ID: php
    Function: pkg.installed
        Name: php5
      Result: None
     Comment: The following packages are set to be installed/updated: php5.
     Started: 23:29:15.906874
    Duration: 217.042 ms
     Changes:   
----------
          ID: install-pear
    Function: cmd.run
        Name: pear uninstall db
pear install db-1.7.14

      Result: False
     Comment: The following requisites were not found:
                                 require:
                                     sls: php
     Started: 
    Duration: 
     Changes:   

Summary
------------
Succeeded: 1 (unchanged=1)
Failed:    1
------------
Total states run:     2

The interesting thing is when I change the require to 'pkg: php' it works as I would expect:

foo:
----------
          ID: php
    Function: pkg.installed
        Name: php5
      Result: None
     Comment: The following packages are set to be installed/updated: php5.
     Started: 23:26:47.362944
    Duration: 221.51 ms
     Changes:   
----------
          ID: install-pear
    Function: cmd.run
        Name: pear uninstall db
pear install db-1.7.14

      Result: None
     Comment: Command "pear uninstall db
              pear install db-1.7.14
              " would have been executed
     Started: 23:26:47.584597
    Duration: 5.816 ms
     Changes:   

Summary
------------
Succeeded: 2 (unchanged=2)
Failed:    0
------------
Total states run:     2

This is a trivialised example, I don't actually want to have a requirement for 'php', I'm actually attempting to chain states in a formula for freepbx I'm working on.

include:
- php
install-pear:
cmd.run:
- name: |
pear uninstall db
pear install db-{{ salt['pillar.get']('pear-db:version', '1.7.14') }}
- cwd: /tmp
- shell: /bin/bash
- timeout: 300
- unless: test `pear info db | fgrep 'Release Version' | grep -o -E '[0-9\.]+'` = {{ salt['pillar.get']('pear-db:version', '1.7.14') }}
- require:
- sls: php
{% from "php/map.jinja" import php with context %}
{% if grains['os_family']=="Debian" %}
{% set use_ppa = salt['pillar.get']('php:use_ppa', none) %}
{% if use_ppa is not none %}
{% set ppa_name = salt['pillar.get']('php:ppa_name', 'ondrej/php5') %}
php54:
pkgrepo.managed:
- ppa: {{ ppa_name }}
pkg.latest:
- name: php5
- refresh: True
{% endif %}
{% endif %}
php:
pkg.installed:
- name: {{ php.php_pkg }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment