Answers: <p>This turns out to be a <a href="https://github.com/saltstack/salt/issues/40771#issuecomment-295406214" rel="noreferrer">known issue</a>:</p>
  
  <blockquote>
    <p>The require_in requisite does not support everything that require does, mainly id does not support sls or state_id without specifying a state module.</p>
  </blockquote>
  
  <p>So by modifying our SLS file to include the state module (specifying <code>file: /root/b</code> as the <code>require_in</code> target instead of simply <code>/root/b</code>), we get the correct result.</p>
  
  <p>I don't know if the other requisite injectors (<code>watch_in</code>, etc.) have the same limitations, so I will likely standardize my coding style on explicitly including module names in such identifiers.</p>
  
Answers: CC BY-SA 3.0
Answers: 2017-04-20T03:02:04.480Z
Answers: 2017-04-20T03:02:04.480Z
Answers: Michael Mol
Body: <p>Given three states, <code>/root/a</code>, <code>/root/b</code> and <code>/root/c</code>, I want <code>/root/c</code> to execute before <code>/root/b</code>, and <code>/root/b</code> to execute before <code>/root/a</code>.</p>
  
  <p>Given a Salt SLS file <code>salt://ordertest/init.sls</code>:</p>
  
  <pre><code>/root/a:
    file.managed:
      - source: salt://ordertest/a
      - user: root
      - group: root
      - mode: 600 
  
  /root/b:
    file.managed:
      - source: salt://ordertest/b
      - user: root
      - group: root
      - mode: 600 
  
  /root/c:
    file.managed:
      - source: salt://ordertest/c
      - user: root
      - group: root
      - mode: 600
  </code></pre>
  
  <p>I can test to see the order in which the listed states would be applied. You'll see <code>/root/a</code> precede <code>/root/b</code>, and <code>/root/b</code> preceed <code>/root/c</code>.</p>
  
  <pre><code>$ salt my-minion-id state.apply ordertest test=True
  my-minion-id:
  ----------
            ID: /root/a
      Function: file.managed
        Result: None
       Comment: The file /root/a is set to be changed
       Started: 13:54:23.538144
      Duration: 31.765 ms
       Changes:
  ----------
            ID: /root/b
      Function: file.managed
        Result: None
       Comment: The file /root/b is set to be changed
       Started: 13:54:23.570065
      Duration: 16.632 ms
       Changes:
  ----------
            ID: /root/c
      Function: file.managed
        Result: None
       Comment: The file /root/c is set to be changed
       Started: 13:54:23.586831
      Duration: 17.124 ms
       Changes:
  
  Summary for my-minion-id
  ------------
  Succeeded: 3 (unchanged=3)
  Failed:    0
  ------------
  Total states run:     3
  Total run time:  65.521 ms
  </code></pre>
  
  <p>If we use <code>require</code> to directly tell <code>/root/b</code> to require <code>/root/</code>, and <code>/root/c</code> to require <code>/root/b</code>:</p>
  
  <pre><code>/root/a:
    file.managed:
      - source: salt://ordertest/a
      - user: root
      - group: root
      - mode: 600
      - require:
        - /root/b
  
  /root/b:
    file.managed:
      - source: salt://ordertest/b
      - user: root
      - group: root
      - mode: 600
      - require:
        - /root/c
  
  /root/c:
    file.managed:
      - source: salt://ordertest/c
      - user: root
      - group: root
      - mode: 600
  </code></pre>
  
  <p>We get the ordering we want:</p>
  
  <pre><code>$ salt my-minion-id state.apply ordertest test=True
  my-minion-id:
  ----------
            ID: /root/c
      Function: file.managed
        Result: None
       Comment: The file /root/c is set to be changed
       Started: 13:32:33.624165
      Duration: 31.807 ms
       Changes:
  ----------
            ID: /root/b
      Function: file.managed
        Result: None
       Comment: The file /root/b is set to be changed
       Started: 13:32:33.656166
      Duration: 17.247 ms
       Changes:
  ----------
            ID: /root/a
      Function: file.managed
        Result: None
       Comment: The file /root/a is set to be changed
       Started: 13:32:33.673589
      Duration: 17.126 ms
       Changes:
  
  Summary for my-minion-id
  ------------
  Succeeded: 3 (unchanged=3)
  Failed:    0
   ------------
  Total states run:     3
  Total run time:  66.180 ms
  </code></pre>
  
  <p>But if we try to use <code>require_in</code> to have <code>/root/c</code> place itself before <code>/root/b</code>:</p>
  
  <pre><code>/root/a:
    file.managed:
      - source: salt://ordertest/a
      - user: root
      - group: root
      - mode: 600
      - require:
        - /root/b
  
  /root/b:
    file.managed:
      - source: salt://ordertest/b
      - user: root
      - group: root
      - mode: 600
  
  /root/c:
    file.managed:
      - source: salt://ordertest/c
      - user: root
      - group: root
      - mode: 600
      - require_in:
        - /root/b
  </code></pre>
  
  <p>It doesn't work; <code>/root/c</code> stays at the end of the sequence:</p>
  
  <pre><code>my-minion-id:
  ----------
            ID: /root/b
      Function: file.managed
        Result: None
       Comment: The file /root/b is set to be changed
       Started: 13:36:54.037214
      Duration: 32.401 ms
       Changes:
  ----------
            ID: /root/a
      Function: file.managed
        Result: None
       Comment: The file /root/a is set to be changed
       Started: 13:36:54.069797
      Duration: 16.968 ms
       Changes:
  ----------
            ID: /root/c
      Function: file.managed
        Result: None
       Comment: The file /root/c is set to be changed
       Started: 13:36:54.086908
      Duration: 17.349 ms
       Changes:
  
  Summary for my-minion-id
  ------------
  Succeeded: 3 (unchanged=3)
  Failed:    0
  ------------
  Total states run:     3
  Total run time:  66.718 ms
  </code></pre>
  
  <p>Here, you can see that <code>/root/b</code> was ordered before <code>/root/a</code> as appropriate, but <code>/root/c</code> did not get ordered before <code>/root/b</code>.</p>
  
  <p>So how can I get this to work? I could use <code>order</code> instead of <code>require</code> and <code>require_in</code>, but that would mean I couldn't use <code>require</code> targeting any state that uses <code>order</code>, which could get quite messy and poorly-defined.</p>
  
Comments: CC BY-SA 3.0
Comments: 2017-04-19T19:02:26.747Z
Comments: I think you may have gotten the wrong letters here; `I want /root/c to execute before /root/b, and /root/b to execute before /root/c` - you have b/c twice?
Comments: Alex
Comments: CC BY-SA 3.0
Comments: 2017-04-19T19:19:14.023Z
Comments: Good catch. My mind went numb preparing this question, thanks to a bunch of formatting headaches. Fixed.
Comments: Michael Mol
Tags: <configuration-management><dependency-management><salt>
Title: Using requisite injection to order states
UserDisplayName: Michael Mol
ThreadText: # Using requisite injection to order states
  
  (Asked by: username_0 on 2017-04-19)
  
  Given three states, `/root/a`, `/root/b` and `/root/c`, I want `/root/c` to execute before `/root/b`, and `/root/b` to execute before `/root/a`.
  
  Given a Salt SLS file `salt://ordertest/init.sls`:
  
  ```
  /root/a:
    file.managed:
      - source: salt://ordertest/a
      - user: root
      - group: root
      - mode: 600 
  
  /root/b:
    file.managed:
      - source: salt://ordertest/b
      - user: root
      - group: root
      - mode: 600 
  
  /root/c:
    file.managed:
      - source: salt://ordertest/c
      - user: root
      - group: root
      - mode: 600
  
  ```
  
  I can test to see the order in which the listed states would be applied. You'll see `/root/a` precede `/root/b`, and `/root/b` preceed `/root/c`.
  
  ```
  $ salt my-minion-id state.apply ordertest test=True
  my-minion-id:
  ----------
            ID: /root/a
      Function: file.managed
        Result: None
       Comment: The file /root/a is set to be changed
       Started: 13:54:23.538144
      Duration: 31.765 ms
       Changes:
  ----------
            ID: /root/b
      Function: file.managed
        Result: None
       Comment: The file /root/b is set to be changed
       Started: 13:54:23.570065
      Duration: 16.632 ms
       Changes:
  ----------
            ID: /root/c
      Function: file.managed
        Result: None
       Comment: The file /root/c is set to be changed
       Started: 13:54:23.586831
      Duration: 17.124 ms
       Changes:
  
  Summary for my-minion-id
  ------------
  Succeeded: 3 (unchanged=3)
  Failed:    0
  ------------
  Total states run:     3
  Total run time:  65.521 ms
  
  ```
  
  If we use `require` to directly tell `/root/b` to require `/root/`, and `/root/c` to require `/root/b`:
  
  ```
  /root/a:
    file.managed:
      - source: salt://ordertest/a
      - user: root
      - group: root
      - mode: 600
      - require:
        - /root/b
  
  /root/b:
    file.managed:
      - source: salt://ordertest/b
      - user: root
      - group: root
      - mode: 600
      - require:
        - /root/c
  
  /root/c:
    file.managed:
      - source: salt://ordertest/c
      - user: root
      - group: root
      - mode: 600
  
  ```
  
  We get the ordering we want:
  
  ```
  $ salt my-minion-id state.apply ordertest test=True
  my-minion-id:
  ----------
            ID: /root/c
      Function: file.managed
        Result: None
       Comment: The file /root/c is set to be changed
       Started: 13:32:33.624165
      Duration: 31.807 ms
       Changes:
  ----------
            ID: /root/b
      Function: file.managed
        Result: None
       Comment: The file /root/b is set to be changed
       Started: 13:32:33.656166
      Duration: 17.247 ms
       Changes:
  ----------
            ID: /root/a
      Function: file.managed
        Result: None
       Comment: The file /root/a is set to be changed
       Started: 13:32:33.673589
      Duration: 17.126 ms
       Changes:
  
  Summary for my-minion-id
  ------------
  Succeeded: 3 (unchanged=3)
  Failed:    0
   ------------
  Total states run:     3
  Total run time:  66.180 ms
  
  ```
  
  But if we try to use `require_in` to have `/root/c` place itself before `/root/b`:
  
  ```
  /root/a:
    file.managed:
      - source: salt://ordertest/a
      - user: root
      - group: root
      - mode: 600
      - require:
        - /root/b
  
  /root/b:
    file.managed:
      - source: salt://ordertest/b
      - user: root
      - group: root
      - mode: 600
  
  /root/c:
    file.managed:
      - source: salt://ordertest/c
      - user: root
      - group: root
      - mode: 600
      - require_in:
        - /root/b
  
  ```
  
  It doesn't work; `/root/c` stays at the end of the sequence:
  
  ```
  my-minion-id:
  ----------
            ID: /root/b
      Function: file.managed
        Result: None
       Comment: The file /root/b is set to be changed
       Started: 13:36:54.037214
      Duration: 32.401 ms
       Changes:
  ----------
            ID: /root/a
      Function: file.managed
        Result: None
       Comment: The file /root/a is set to be changed
       Started: 13:36:54.069797
      Duration: 16.968 ms
       Changes:
  ----------
            ID: /root/c
      Function: file.managed
        Result: None
       Comment: The file /root/c is set to be changed
       Started: 13:36:54.086908
      Duration: 17.349 ms
       Changes:
  
  Summary for my-minion-id
  ------------
  Succeeded: 3 (unchanged=3)
  Failed:    0
  ------------
  Total states run:     3
  Total run time:  66.718 ms
  
  ```
  
  Here, you can see that `/root/b` was ordered before `/root/a` as appropriate, but `/root/c` did not get ordered before `/root/b`.
  
  So how can I get this to work? I could use `order` instead of `require` and `require_in`, but that would mean I couldn't use `require` targeting any state that uses `order`, which could get quite messy and poorly-defined.
  
  **Tags:** configuration-management, dependency-management, salt
  
  > **Comments:**
  > **username_1**: I think you may have gotten the wrong letters here; `I want /root/c to execute before /root/b, and /root/b to execute before /root/c` - you have b/c twice?  
  > **username_0**: Good catch. My mind went numb preparing this question, thanks to a bunch of formatting headaches. Fixed.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-04-20. Score: 5 | Accepted answer
  
  This turns out to be a [known issue](https://github.com/saltstack/salt/issues/40771#issuecomment-295406214):
  
  > The require\_in requisite does not support everything that require does, mainly id does not support sls or state\_id without specifying a state module.
  
  So by modifying our SLS file to include the state module (specifying `file: /root/b` as the `require_in` target instead of simply `/root/b`), we get the correct result.
  
  I don't know if the other requisite injectors (`watch_in`, etc.) have the same limitations, so I will likely standardize my coding style on explicitly including module names in such identifiers.
  
  
  ---
  
  