Using su_user with use_su_login yields an error with a macOS target
See original GitHub issueDescribe the bug Using su_user with use_su_login yields an error with a macOS target. Using use_su_login alone works without specifying the user, but it does not seem to load and shell profiles (nor .zshrc or .bash_profile):
-> Proposed changes:
Groups: mac_vms
[vm] Operations: 1 Commands: 1
--> Beginning operation run...
--> Starting operation: Test ruby ("commands=['which ruby']",)
[pyinfra\api\operations] Starting operation Test ruby on vm
[pyinfra\api\connectors\ssh] Running command on vm: (pty=None) su -l the_user -s `which sh` -c 'which ruby'
[vm] >>> su -l the_user -s `which sh` -c 'which ruby'
[vm] su: Sorry
[pyinfra\api\connectors\ssh] Waiting for exit status...
[pyinfra\api\connectors\ssh] Command exit status: 1
[vm] Error
[pyinfra\api\state] Failing hosts: vm
No hosts remaining!
--> ←[31m←[1mpyinfra error←[0m:
To bring some context:
I have a target macOS machine with chruby set up using a specific version of ruby, under .rubies built with ruby-install. I want to install some gems on the target machine with pyinfra, but this requires it to have chruby run beforehand so that it selects the correct gem version, instead of the one pre-installed with macOS. The commands to do this are in the .zshrc, and when I login to an SSH shell it works as intended. However, even when running with use_su_login = True
, it returns the incorrect version of ruby:
server.shell(
name = 'Test ruby'
,use_su_login = True
,commands = [ 'which ruby' ]
)
# Results in:
[vm] >>> sh -c 'which ruby'
[vm] /usr/bin/ruby
From an SSH login shell:
> which ruby
/Users/USER/.rubies/ruby-2.7.1/bin/ruby
To Reproduce
With a macOS target (my target is Catalina 10.15.6) such an operation with both su_user
and use_su_login
specified:
server.shell(
name = 'Test ruby'
,su_user = host.data.user
,use_su_login = True
,commands = [ 'which ruby' ]
)
Expected behavior No errors to occur
Meta
- Include output of
pyinfra --support
. Note that I am on 1.0.2 as I ran into some other issues with since 1.0.3. I plan to report the issues as well as soon as I resolve this so I can continue with the other ops.
System: Windows
Platform: Windows-10-10.0.19041-SP0
Release: 10
Machine: AMD64
pyinfra: v1.0.2
Executable: C:\Users\the_user\AppData\Local\Programs\Python\Python38-32\Scripts\pyinfra.exe
Python: 3.8.3 (CPython, MSC v.1925 32 bit (Intel))
- How was pyinfra installed (source/pip)? pip
Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (13 by maintainers)
Top GitHub Comments
Thanks for testing @harold-b - I’ve added https://github.com/Fizzadar/pyinfra/issues/426 to track the login shell issue 😬
Excellent! Thanks for your hard work. I will have a try with the new version as soon as I can and report back for confirmation.