无法从ansible playbook

时间:2015-08-25 04:42:54

标签: bash shell ansible ansible-playbook sage

我试图通过ansible playbook在后台运行两个shell脚本。 该剧本已成功运行并显示所有任务已成功运行。

但是这两个shell脚本没有运行。 我用这个检查过:

ps -ef | grep sh

这两个shell脚本是运行sage服务所必需的,我正在尝试自动化s 使用ansible的age服务器配置。 以下是剧本的样子:

---
- hosts: localhost
  remote_user: root

  tasks:
   - name : update system
     shell : apt-get update

   - name : install dependencies
     shell : apt-get install -y m4 build-essential gcc gfortran libssl-dev

   - name : install python-software-properties
     shell : apt-get install python-software-properties

   - name : add sage ppa repo
     shell : apt-add-repository ppa:aims/sagemath

   - name : update system
     shell : apt-get update

   - name : install dvipng
     shell : apt-get install dvipng

   - name : install sage binary
     shell : apt-get install sagemath-upstream-binary

   - name : run create sage script
     shell : . ./create_sagenb &

   - name : run start sage script
     shell : . ./start_sage &

这就是create_sagenb的样子:

#!/bin/bash
# Creating Sage notebook
screen -S "Sage_Server" sage -c 'notebook(interface="",directory="/root/.sage/sage_notebook.sagenb",port=80,accounts=true)'

这就是start_sage的外观:

#!/bin/bash
# Creating Sage notebook
address=$(hostname --ip-address)
screen -S "Sage_Server" sage -c "notebook(interface=" "'$address'" ",port=80,accounts=true)"

1 个答案:

答案 0 :(得分:1)

这就是我在Ansible中成功调用屏幕会话的方法:

- name: Invoke script
  command: /usr/bin/screen -d -m sudo -u myuser /usr/local/bin/myuser.sh -i -y

这将以分离模式(-d和-m组合)启动一个屏幕会话,然后我使用sudo切换到特定用户来运行我的脚本。