项目作者: giladsh1

项目描述 :
EC2 interaction tool
高级语言: Python
项目地址: git://github.com/giladsh1/ec2-ninja.git
创建时间: 2017-03-20T07:59:44Z
项目社区:https://github.com/giladsh1/ec2-ninja

开源协议:MIT License

下载


ec2-ninja

Forked from ssh2, ec2-ninja is an interactive command line tool which allows you to control your EC2 instances.

in additional to ssh capabilities, ec2-ninja allows you to:

  • run ssh commands
  • copy file to ec2 instances
  • copy files from ec2 instances and compare (md5 check)
  • open ssh-tunnel

Requirements

  • AWS CLI
  • Python
  • Python pip
  • pip packages (prettytable, PyYAML, boto3) - install with pip install -r requirements.txt

usage

ec2-ninja has the following flags -

  1. Options:
  2. -h, --help: show this help message and exit
  3. -x, --bust-cache: re-fetch servers list from AWS
  4. -d, --use-cache: force load from disk - override conf file ignore cache option
  5. -u USER, --user=USER: provide user
  6. -i IDENTITY, --identity=IDENTITY: provide identity file
  7. --passwd: don't use ssh keys, prompt for password
  8. -p PROFILE, --profile=PROFILE: provide AWS profile
  9. -r REGION, --region=REGION: provide AWS region
  10. -g GREP, --grep=GREP: filter the server list
  11. --ungrep=UNGREP: ungrep - exclude from servers list
  12. --split: open shell panes for each node found - up to 15
  13. --limit=LIMIT: limit the number of panes to open
  14. -e COMMAND, --exec=COMMAND: run a single command
  15. -s SLEEP, --sleep=SLEEP: sleep between ssh runs, cancel parallel run
  16. --exit-status=EXIT_CODE: filter exec exit code outcome - supply 'passed' or 'failed'
  17. --batch-size=BATCH: batch size to run - this is relevant when a sleep is supplied
  18. --copy=COPY: copy a file to remote host, must be supplied with --dest option
  19. --dest=DEST: destination for file copy, must be supplied with the --copy option
  20. --owner=OWNER: change the owner of the file after copying, must be supplied with --copy/--dest option
  21. --copy-remote=REMOTE: copy a file from the remote server to local folder
  22. --dest-remote=REMOTE_DEST: path to save files from remote-copy (optional, default copy path is ~/.cache)
  23. --tunnel=TUNNEL: ssh tunnel to the instance - provide as <local-port>:<remote-port> or <local-port> only for the same port
  24. --ip-type=IPTYPE: choose between lan and wan address (wan is the default)
  25. -l, --list: show only list (without ssh to instance)

example usage

split panes:

list ec2 instances with lan IP:

execute a command on remote hosts:

copy a file to remote hosts:

copy from remote hosts and compare:

open ssh-tunnel connection (port forwarding):

config file

ec2-ninja also suport a config file, which can hold default values.
the file must be saved as ~/.ec2-ninja.yaml.
the following options are valid -

  1. # ec2-ninja conf file
  2. # This file must be saved as: ~/.ec2-ninja.yaml
  3. default_user: ubuntu # use as default user
  4. default_ip_type: lan # use as default ip type
  5. ignore_cache: yes # always refresh from AWS, don't use local cache file (unless -d option is used)
  6. batch_size: 20 # change default ssh batch size (depending on your intermet connection, cpu, etc)
  7. #### multiple regions per profile ####
  8. # when defined, ec2-ninja will automatically fetch servers from all regions
  9. # you can override this default value with the --region option
  10. multi_region:
  11. default:
  12. - us-east-1
  13. - us-west-2
  14. prod:
  15. - us-east-1
  16. - eu-central-1
  17. qa:
  18. - us-east-1
  19. - eu-central-1
  20. #### bastion hosts ####
  21. # for each bastion host, you must define an IP address and user.
  22. # you can also define an additional ssh key (full path), if it's not your in ssh-agent's keychain.
  23. # if a host is found for the current profile and region, it will be automatically used
  24. bastion_hosts:
  25. prod:
  26. us-east-1:
  27. ip: <ip-address>
  28. user: <user>
  29. eu-central-1:
  30. ip: <ip-address>
  31. user: <user>

Installation

  1. git clone https://github.com/giladsh1/ec2-ninja.git
  2. cd ec2-ninja
  3. ln -sf $(pwd)/ec2-ninja /usr/local/bin/

Author

Gilad Sharaby, giladsh1@gmail.com