Skip to content
Grant Heffernan edited this page Jan 8, 2016 · 1 revision

Generate and update SSH configuration files, or alternatively return a list of IPs for matching stacks.

Host names are based off the stack naming convention, project_name::env::region. The default is to use public instance IPs (or elastic ip if one is assigned). Passing the --private option will instead use instance private IPs.

For example, if we have a host 'api1' in the stack apiaxle::prod::us-east, the resultant hostname will be api1-apiaxle-prod-us-east

By default, opsworks ssh will iterate over all stacks. If you wish to restrict the stacks it searches, simply pass the stack name (or a partial match) as an argument:

opzworks ssh myproject::prod

If you wanted to automatically scrape all your stacks to populate your ssh config, and you don't want to use the --update flag (which will overwrite the entire file contents), you could do something like:

  • add a crontab entry similar to: 0 * * * * /bin/bash -l -c /path/to/opzworks-ssh.sh
  • create /path/to/opzworks-ssh.sh:
# this script reads .ssh/config, drops anything after the matched line,
#   then generates a list of opsworks hosts and appends them to the file.
gsed -i '/OPSWORKS_CRON_LINE_MATCH/q' ~/.ssh/config
opzworks ssh >>~/.ssh/config

Note this example assumes the use of a gnu sed-like utility, which on OSX means installing gnu sed (brew install gsed if you're using homebrew). On Linux, simply change gsed to sed.

Add the following line to the bottom of your existing ~/.ssh/config:

# OPSWORKS_CRON_LINE_MATCH

To return only a list of IPs, pass the --raw flag:

opzworks ssh -r mystack1 mystack2 or opzworks ssh -r -p mystack, etc.

Clone this wiki locally