Reputation: 8052
I would like to set up a tmuxinator project to open a dynamic number of tmux windows. In my scenario I would like one window per instance in an AWS Auto Scale Group.
I have a bash function to list the private IP of each server I want to attach to. For example:
$ prod-ips
10.X.X.1
10.X.X.2
10.X.X.3
10.X.X.4
I have a bash function to tunnel to any of those IPs:
$tunnel_to 10.X.X.1
....
works
[email protected] ~ $
How do I pass the IP list returned from prod-ips
into a tmuxinator project so that it will open 1 window for each line of output ?
Thanks!
Upvotes: 1
Views: 582
Reputation: 8052
Thanks @pdoherty926, the ERB syntax is what I was looking for.
Looks like functions defined in my bash_profile
will not work, but if I write those functions out in the tmuxinator conf then it all works:
This works (the echo is the output of prod-ips consolidated into a single line):
windows:
<%- `echo 10.250.XX.X1,10.250.XX.X2,10.250.XX.X3`.split(',').each do |ip| %>
- ip-<%= ip.chomp %>: tunnel_to <%= ip %>
<%- end %>
But this command does not work:
windows:
<%- `prod-ips`.split("\n").each do |ip| %>
- ip-<%= ip.chomp %>: tunnel_to <%= ip %>
<%- end %>
But if I defined prod-ips
long hand in the file the tmuxinator start command works:
windows:
<%- `aws ec2 describe-instances | jq '.Reservations[].Instances[] | select(has("SecurityGroups")) | select(.SecurityGroups | length > 0) | select(.SecurityGroups[0].GroupName | test("<SECURITYGROUPFILTER>")) | .PrivateIpAddress' | sed -e 's/"//g'`.split("\n").each do |ip| %>
- ip-<%= ip.chomp %>: tunnel_to <%= ip %>
<%- end %>
Upvotes: 0
Reputation: 10349
Since project files are first processed as ERB, you could do something like the following:
# ~/.tmuxinator/dyn.yml
name: dyn
root: ~/
windows:
# just using `echo` as a POC; this is where you'd make your function call
<%- `echo "111,222,333"`.split(',').each do |ip| %>
- tunnel-to-<%= ip.chomp %>: echo tunnel_to <%= ip %>
<%- end %>
Upvotes: 1