Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd with runas and cwd gives problems #586

Closed
bastichelaar opened this issue Jan 27, 2012 · 1 comment
Closed

cmd with runas and cwd gives problems #586

bastichelaar opened this issue Jan 27, 2012 · 1 comment
Milestone

Comments

@bastichelaar
Copy link

Because it sets the environment (using "su - user -c command"), the cwd is ignored and the command is ran from the users homedirectory. There is an option with_env, but its not proper implemented yet. Also, I cant override the with_env from the run command.

@codysoyland
Copy link
Contributor

It seems that "su - " sets the environment and resets the cwd. The cwd can be set back by prefixing the command with a "cd" statement, which is what the following patch does:

diff --git a/salt/modules/cmdmod.py b/salt/modules/cmdmod.py
index a69a9c5..9fdb15a 100644
--- a/salt/modules/cmdmod.py
+++ b/salt/modules/cmdmod.py
@@ -81,6 +81,7 @@ def _run(cmd,
         # Load the 'nix environment
         if with_env:
             cmd_prefix += ' - '
+            cmd = 'cd ' + cwd + ' && ' + cmd

         cmd_prefix += runas + ' -c'
         cmd = '{0} "{1}"'.format(cmd_prefix, cmd)

arthurzenika pushed a commit to arthurzenika/salt that referenced this issue Sep 17, 2013
tacerus pushed a commit to tacerus/salt that referenced this issue May 30, 2024
* Mark Salt 3006 as released

Without this, commands like

```
salt '*' salt_version.equal 'Sulfur'
```

will not work properly and return False although Salt 3006 is used.

Signed-off-by: Dominik Gedon <[email protected]>

* Fix detection of Salt codename by salt_version module

* Fix mess with version detection bad version definition

* Add some new and fix unit tests

* Fix SaltStackVersion string for new versions format

* Do not crash when passing numbers to 'salt_version.get_release_number'

* Fix salt_version execution module documentation

---------

Signed-off-by: Dominik Gedon <[email protected]>
Co-authored-by: Pablo Suárez Hernández <[email protected]>
meaksh added a commit to meaksh/salt that referenced this issue Nov 12, 2024
* Mark Salt 3006 as released

Without this, commands like

```
salt '*' salt_version.equal 'Sulfur'
```

will not work properly and return False although Salt 3006 is used.

Signed-off-by: Dominik Gedon <[email protected]>

* Fix detection of Salt codename by salt_version module

* Fix mess with version detection bad version definition

* Add some new and fix unit tests

* Fix SaltStackVersion string for new versions format

* Do not crash when passing numbers to 'salt_version.get_release_number'

* Fix salt_version execution module documentation

---------

Signed-off-by: Dominik Gedon <[email protected]>
Co-authored-by: Pablo Suárez Hernández <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants