Answers: <h2>Edit update April 3rd 2023:</h2>
  <p>As of salt 3006 (<a href="https://salt.tips/whats-new-in-salt-sulfur/#umask" rel="nofollow noreferrer">https://salt.tips/whats-new-in-salt-sulfur/#umask</a>) umask is now a global state argument and can be specified on any state.</p>
  <h2>Original work around for pre 3006</h2>
  <p>I ended up working around this by creating a custom state module that wraps any state that I want to set the umask for:</p>
  <p>_states/umask.py:</p>
  <pre class="lang-py prettyprint-override"><code>import os
  
  def wrap(wrapped_state, mask, *args, **kwargs):
      old_umask = None
      try:
          if not __opts__[&quot;test&quot;]:
              old_umask = os.umask(int(mask, base=8))
          return __states__[wrapped_state](*args, **kwargs)
      finally:
          if old_umask is not None:
              os.umask(old_umask)
  </code></pre>
  <p>Usage:</p>
  <pre><code>&quot;install python requests package&quot;:
    umask.wrap:
      - wrapped_state: pip.installed
      - mask: '022'
      - name: requests
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2022-12-01T19:36:23.353Z
Answers: 2023-04-03T13:09:42.807Z
Answers: 2023-04-03T13:09:42.807Z
Answers: bdrx
Answers: <p><strong>This answer is for versions &lt;3006</strong></p>
  <p>No, there's no facility for changing the umask of the running Salt process.</p>
  <p>What you could do is start a new process with <code>cmd.run</code>:</p>
  <pre class="lang-yaml prettyprint-override"><code>install python module:
    cmd.run:
      - name: pip install foo
      - umask: '077'
      - unless:
        - fun: pip.is_installed
          pkgname: foo
  
  install python module at version:
    cmd.run:
      - name: pip install bar==4.2
      - umask: '077'
      - unless:
        - pip freeze | grep bar==4.2
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2022-09-12T14:46:16.330Z
Answers: Is there a way to specify a specific version and/or a `>=` version to the `pip.is_installed` function?
Answers: bdrx
Answers: CC BY-SA 4.0
Answers: 2022-09-12T14:52:40.427Z
Answers: @bdrx no, but see edit
Answers: OrangeDog
Answers: CC BY-SA 4.0
Answers: 2022-09-12T14:36:09.150Z
Answers: 2023-04-05T08:51:22.217Z
Answers: 2023-04-05T08:51:22.217Z
Answers: OrangeDog
Body: <p>Is there a way to set the umask for the pip state module or is there a more generic way to set the umask before specific state modules are run? In ansible the pip module takes a umask parameter. I do not see an equivalent option in the salt pip state module. We run salt-call with a umask of 007 but we need to install certain python packages with more open permissions; is there a way to do this?</p>
  
Tags: <salt>
Title: Set umask for an individual salt state
UserDisplayName: bdrx
ThreadText: # Set umask for an individual salt state
  
  (Asked by: username_0 on 2022-08-25)
  
  Is there a way to set the umask for the pip state module or is there a more generic way to set the umask before specific state modules are run? In ansible the pip module takes a umask parameter. I do not see an equivalent option in the salt pip state module. We run salt-call with a umask of 007 but we need to install certain python packages with more open permissions; is there a way to do this?
  
  **Tags:** salt
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2022-12-01. Score: 2 | Accepted answer
  
  ## Edit update April 3rd 2023:
  
  As of salt 3006 (<https://salt.tips/whats-new-in-salt-sulfur/#umask>) umask is now a global state argument and can be specified on any state.
  
  ## Original work around for pre 3006
  
  I ended up working around this by creating a custom state module that wraps any state that I want to set the umask for:
  
  \_states/umask.py:
  
  ```py
  import os
  
  def wrap(wrapped_state, mask, *args, **kwargs):
      old_umask = None
      try:
          if not __opts__["test"]:
              old_umask = os.umask(int(mask, base=8))
          return __states__[wrapped_state](*args, **kwargs)
      finally:
          if old_umask is not None:
              os.umask(old_umask)
  
  ```
  
  Usage:
  
  ```
  "install python requests package":
    umask.wrap:
      - wrapped_state: pip.installed
      - mask: '022'
      - name: requests
  
  ```
  
  
  ---
  
  ### Answer by username_1 on 2022-09-12. Score: 1
  
  **This answer is for versions <3006**
  
  No, there's no facility for changing the umask of the running Salt process.
  
  What you could do is start a new process with `cmd.run`:
  
  ```yaml
  install python module:
    cmd.run:
      - name: pip install foo
      - umask: '077'
      - unless:
        - fun: pip.is_installed
          pkgname: foo
  
  install python module at version:
    cmd.run:
      - name: pip install bar==4.2
      - umask: '077'
      - unless:
        - pip freeze | grep bar==4.2
  
  ```
  
  > **Comments:**
  > **username_0**: Is there a way to specify a specific version and/or a `>=` version to the `pip.is_installed` function?  
  > **username_1**: @username_0 no, but see edit  
  
  ---
  
  