这个问题在这里已有答案:
在yaml playbook下面重新启动jboss服务器但是没有返回控制来执行下一个ansible命令 . 我还使用等待模块停止等待当前命令结果并转到下一个命令 . 但是,ansbile仍无限期地依赖当前命令 . 我出错的时候请告诉我?
---
- hosts: test1
tasks:
- name: simple command
become: true
command: whoami
register: output
- debug:
msg: "I gave the command whoami and the out is '{{output.stdout}}'"
- name: change to jboss user
become: true
become_user: jboss
command: whoami
register: output
- debug:
msg: "I gave the command whoami and the out is '{{output.stdout}}'"
- name: start jboss server as jboss user
become: true
become_user: jboss
command: sh /usr/jboss/bin/run.sh -c XXXXXXXX -b x.x.x.x &
when: inventory_hostname in groups['test1']
register: restartscript
- debug:
msg: "output of server restart command is '{{restartscript.stdout}}'"
- name: waiting for server to come back
local_action:
module: wait_for
timeout=20
host=x.x.x.x
port=8080
delay=6
state=started
终端输出消息
Build 用户的SSH连接:XXXXXXXXXXX SSH:EXEC sshpass -d12 ssh -vvv -C -o ControlMaster = auto -o ControlPersist = 60s -o User = XXXXXXXXX -o ConnectTimeout = 10 -o ControlPath = / home / tcprod / XXXXXXXXXX / . ansible / cp / ansible-ssh-%h-%p-%r -tt XXXX'/ bin / sh -c'“'''sudo -H -S -p”[sudo via ansible,key = hvgwnsbxpkxvbcmtcfvvsplfphdrevxg]密码: “-u jboss / bin / sh -c'”'''''''''''''''echo BECOME-SUCCESS-hvgwnsbxpkxvbcmtcfvvsplfphdrevxg; / usr / bin / python /tmp/ansible-tmp-XXXXXXXXX.XX-XXXXXXXXXXXXXX/command.py'“''''''''''''''''&& sleep 0'”'''''
1 回答
在Ansible“命令”中不允许使用& .
尝试删除它或使用shell而不是命令 .
来自Ansible documentation about command: