Skip to main content

A Python package to execute code remotely to multiple operating system platforms

Project description

rudder

rudder is a Python package to run commands remotely on Windows, macOS or *nix systems using PowerShell Remoting/WinRM or SSH.

Getting Started

In order to use rudder you must make sure you have access and credentials to authenticate to a remote host.

Prerequisites

The following packages will be installed and are prerequisities for rudder:

paramiko
fire
pypsrp

NOTE: To use this on your remote Windows machines, you need to do the following:

  1. Run from an elevated PowerShell prompt
winrm quickconfig (type yes)
Enable-PSRemoting (type yes)
# Set start mode to automatic
Set-Service WinRM -StartMode Automatic
# Verify start mode and state - it should be running
Get-WmiObject -Class win32_service | Where-Object {$_.name -like "WinRM"}
  1. Additionally you may need to specify the allowed host to remote into systems:
# Trust hosts
Set-Item 'WSMan:localhost\client\trustedhosts' -value * -Force 
NOTE: don't use the * for the value parameter in production - specify your Swimlane instance IP
# Verify trusted hosts configuration
Get-Item WSMan:\localhost\Client\TrustedHosts
  1. Additional 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 Profile
Get-NetConnectionProfile

# if the NetworkCategory is set to Public then run the following to set it to Private

Set-NetConnectionProfile -InterfaceAlias Ethernet0 -NetworkCategory Private
# try it again

Installing

Install this package using pip:

pip3 install rudder

Or you can clone this repository and install locally:

git clone https://github.com/MSAdministrator/rudder.git
cd rudder
python3 setup.py install

Usage

Below 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 a Host object. You do this by importing the Host class in your script like so. Once imported you can provide a list of one or more Host objects to rudder (more info below):

from rudder import Host

my_host_list = []
my_host_list.append(
    Host(
        hostname=None, # nix & windows
        username=None, # nix & windows
        password=None, # nix & windows
        verify_ssl=False, # windows
        ssh_key_path=None, # nix
        port=22, # nix
        timeout=5, # nix
    )
)

Running Command Remotely Using Username & Password

With rudder you can run either ssh, cmd or powershell commands remotely. Below are examples of these methods:

from rudder import Rudder, Host

my_host_list = []
my_host_list.append(
    Host(
        hostname='10.10.32.100',
        username='admin',
        password='secret_password1'
    )
)

rudder = Rudder(hosts=my_host_list)
for result in rudder.execute(executor='powershell', command='Get-ChildItem -Path "C:\" -Recurse'):
    print(result)

Running Command Remotely using SSH key

With rudder you can run commands remotely using SSH and whichever shell is avaialble on the remote system:

from rudder import Rudder, Host

my_host_list = []
# If no ssh_key_path or no username and password, Rudder
# will attempt to use the default path for these keys
my_host_list.append(
    Host(
        hostname='10.10.32.100'
    )
)

my_host_list.append(
    Host(
        hostname='10.32.1.1',
        ssh_key_path='~/some_path
    )
)

rudder = Rudder(hosts=my_host_list)
for result in rudder.execute(executor='ssh', command='ls -al'):
    print(result)

Running Command Remotely using Config File

With 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 them
  windows1: # <- This can be any name but make it clear to you
    inputs: # <- How I am going to authenticate to these hosts
      username: some_username
      password: secret_password
      verify_ssl: false
    hosts: # <- 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 needed
  linux1:
    inputs: # <- How I am going to authenticate to these hosts
      username: some_username
      password: secret_password
      ssk_key_path: path_to_a_ssh_private_key
      port: 22
      timeout: 5
    hosts: # <- 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 needed

run_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
      - linux1
    command: | # <- The command to run on all the inventory defintions above
      ls -al
  my_windows_group_name:
    executor: powershell # or cmd
    inventories:
      - windows1
    command: |
      Get-ChildItem

By 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 a Rudder object then all you need to do is call the execute method with no additional paramter values.

from rudder import Rudder

rudder = Rudder(config_file_path='~/path_to_config_file.yml')
for result in rudder.execute():
    print(result)

Built With

  • carcass - Python packaging template

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rudder-0.2.0.tar.gz (11.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

rudder-0.2.0-py3.6.egg (22.8 kB view details)

Uploaded Egg

rudder-0.2.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file rudder-0.2.0.tar.gz.

File metadata

  • Download URL: rudder-0.2.0.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.20.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.5

File hashes

Hashes for rudder-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7a5e73450f310b6632618dc1cbd9efec463e183a67fa408a60c694880659becc
MD5 ae962d8722a738c99e3dfa8ba61dd0d0
BLAKE2b-256 eb99748004535ee994d3acc1a530d2cc4334396435d0934abb9befc31503fca2

See more details on using hashes here.

File details

Details for the file rudder-0.2.0-py3.6.egg.

File metadata

  • Download URL: rudder-0.2.0-py3.6.egg
  • Upload date:
  • Size: 22.8 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.20.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.5

File hashes

Hashes for rudder-0.2.0-py3.6.egg
Algorithm Hash digest
SHA256 9df6cfd8b693c1f5624d858d532768e186d1c24421dbe986103c00f1362e2408
MD5 b1089b38240a899f6917f77e7ff13611
BLAKE2b-256 f443dcc1da8fc70e883c451f9b6bab8942c57ef5916d0ca3fb693ea5dff930cf

See more details on using hashes here.

File details

Details for the file rudder-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: rudder-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.20.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.5

File hashes

Hashes for rudder-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 74f68688a68bfced550b144d69c36b56a061bc2de393c3ef30ed272329243255
MD5 9a2632c51551de75aff169bb2c1a652d
BLAKE2b-256 de60e0eb2d1e7373d34898c6a07a899f54ab5bce841d63bdc3010ee4d4aac44f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page