Problem
I have a simple Ansible playbook that creates a list of tmux
sessions and then runs a script inside of each session. I am trying to give the tmux
sessions names in my vars.yml
file.
My problem is that I want to run the same command in all of the tmux
sessions I create. Here is the simple playbook I have.
Playbook
Obviously the playbook is broken in its current form. I having a hard time of figuring out how to:
- Navigate to the correct directory for each unique
tmux
session (to a directory with the same name as the session) - Start a script (same name shared in all sessions) in the folder navigated to
.
---
- hosts: all
vars_file:
- vars.yml
tasks:
- name: "Create tmux sessions for each server."
command: tmux new -d -s {{ servers }}
- name: "Start each server in its tmux session."
shell: >
tmux send-keys -t {{ servers }} "./start.sh" Enter
Variables
---
# Name of all tmux sessions running on server
servers:
- creative
- development
- lobby
- proxy
- survival
- workflow
Any tips for how I might be able to intelligently refer to the current variable executing within the shell command (e.g. cd ~/{{ current_variable }}/scripts/ && ./start.sh
)? Thanks!