我有一个简单的Ansible手册,创build一个tmux会话列表,然后在每个会话中运行一个脚本。 我想在我的vars.yml文件中给tmux会话名称。
我的问题是,我想在我创build的所有tmux会话中运行相同的命令。 这是我有的简单的手册。
剧本显然是以目前的forms被打破的。 我很难搞清楚如何:
tmux会话的正确目录(到与会话同名的目录) 。
--- - 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
--- # Name of all tmux sessions running on server servers: - creative - development - lobby - proxy - survival - workflow
有关如何能够智能地引用当前在shell命令中执行的variables(例如cd ~/{{ current_variable }}/scripts/ && ./start.sh )的cd ~/{{ current_variable }}/scripts/ && ./start.sh ? 谢谢!
你需要遍历你的剧本中的serversvariables:
在1.x中,这将会完成:
--- - hosts: all vars_file: - vars.yml tasks: - name: "Create tmux sessions for each server." command: tmux new -d -s {{ item }} with_items: servers - name: "Start each server in its tmux session." shell: > tmux send-keys -t {{ item }} "./start.sh" Enter with_items: servers
在2.x中,您需要引用with_items指令所使用的variables: "{{ servers }}" 。