Package: rudder
rudderrudderis a Python package to run commands remotely on Windows, macOS or *nix systems using PowerShell Remoting/WinRM or SSH.Getting StartedIn order to use rudder you must make sure you have access and credentials to authenticate to a remote host.PrerequisitesThe following packages will be installed and are prerequisities for rudder:paramiko==2.7.2
fire==0.4.0
pypsrp==0.5.0
pyyaml==5.4.1NOTE: To use this on your remote Windows machines, you need to do the following:Run from an elevated PowerShell promptwinrmquickconfig(typeyes)Enable-PSRemoting(typeyes)# Set start mode to automaticSet-ServiceWinRM-StartModeAutomatic# Verify start mode and state - it should be runningGet-WmiObject-Classwin32_service|Where-Object{$_.name-like"WinRM"}Additionally you may need to specify the allowed host to remote into systems:# Trust hostsSet-Item'WSMan:localhost\client\trustedhosts'-value*-ForceNOTE:don'tusethe*forthevalueparameterinproduction-specifyyourSwimlaneinstanceIP# Verify trusted hosts configurationGet-ItemWSMan:\localhost\Client\TrustedHostsAdditional Troubleshooting#If you receive a timeout error or something like that, check and make sure that your remote Windows host network is set to Private and NOT public. You can change it using the following:# Get Network ProfileGet-NetConnectionProfile# if the NetworkCategory is set to Public then run the following to set it to PrivateSet-NetConnectionProfile-InterfaceAliasEthernet0-NetworkCategoryPrivate# try it againInstallingInstall this package usingpip:pip3installrudderOr you can clone this repository and install locally:gitclonehttps://github.com/MSAdministrator/rudder.gitcdrudder
python3setup.pyinstallUsageBelow contains two prime examples of using rudder on both Windows and a *nix system.Whether you are wanting to run a command remotely on Windows or a *nix based system (e.g. CentOS, macOS, etc.) you first need to create aHostobject.  You do this by importing theHostclass in your script like so. Once imported you can provide a list of one or moreHostobjects to rudder (more info below):fromrudderimportHostmy_host_list=[]my_host_list.append(Host(hostname=None,# nix & windowsusername=None,# nix & windowspassword=None,# nix & windowsverify_ssl=False,# windowsssh_key_path=None,# nixprivate_key_string=None,# nixport=22,# nixtimeout=5,# nix))Running Command Remotely Using Username & PasswordWith rudder you can run eitherssh,cmdorpowershellcommands remotely.  Below are examples of these methods:fromrudderimportRudder,Hostmy_host_list=[]my_host_list.append(Host(hostname='10.10.32.100',username='admin',password='secret_password1'))rudder=Rudder(hosts=my_host_list)forresultinrudder.execute(executor='powershell',command='Get-ChildItem -Path "C:\"-Recurse'):print(result)Running Command Remotely using SSH keyWith rudder you can run commands remotely using SSH and whichever shell is avaialble on the remote system:fromrudderimportRudder,Hostmy_host_list=[]# If no ssh_key_path or no username and password, Rudder# will attempt to use the default path for these keysmy_host_list.append(Host(hostname='10.10.32.100'))my_host_list.append(Host(hostname='10.32.1.1',ssh_key_path='~/some_path#private_key_string='some_private_key_as_string'))rudder=Rudder(hosts=my_host_list)forresultinrudder.execute(executor='ssh',command='ls -al'):print(result)Running Command Remotely using Config FileWith rudder you can provide a formatted config file to automate rudder even further. Below is an example of the format of this configuration file:inventory:# Inventory contains one or more groups of hosts and how you can authenticate to themwindows1:# <- This can be any name but make it clear to youinputs:# <- How I am going to authenticate to these hostsusername:some_usernamepassword:secret_passwordverify_ssl:falsehosts:# <- A list of one or more hosts that work with the provided inputs above-192.168.1.1-10.32.1.1# Add as many as neededlinux1:inputs:# <- How I am going to authenticate to these hostsusername:some_usernamepassword:secret_passwordssk_key_path:path_to_a_ssh_private_key#private_key_string: some_private_key_as_string_valueport:22timeout:5hosts:# <- A list of one or more hosts that work with the provided inputs above-10.32.100.201-10.32.0.1# Add as many as neededrun_conditions:some_group_name:# <- A grouping of one or more inventories (hosts)executor:ssh# <- The executor to use. Options are ssh, cmd, powershell.inventories:# <- One or more inventory defintions from above-linux1command:|# <- The command to run on all the inventory defintions abovels -almy_windows_group_name:executor:powershell# or cmdinventories:-windows1command:|Get-ChildItemBy providing a path to this configuration file to rudder will parse the config file and ensure it's in it's expected format.After you have instantiated aRudderobject then all you need to do is call theexecutemethod with no additional paramter values.fromrudderimportRudderrudder=Rudder(config_file_path='~/path_to_config_file.yml')forresultinrudder.execute():print(result)Built Withcarcass- Python packaging templateContributingPlease readCONTRIBUTING.mdfor details on our code of conduct, and the process for submitting pull requests to us.VersioningWe useSemVerfor versioning.AuthorsMSAdministrator -Initial work-MSAdministratorSee also the list ofcontributorswho participated in this project.LicenseThis project is licensed under the MIT License - see theLICENSEfile for details