【问题标题】:starting jboss server using ansible and returning back control [duplicate]使用ansible启动jboss服务器并返回控制[重复]
【发布时间】:2016-12-08 20:03:23
【问题描述】:

下面的 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

终端输出信息

为用户建立 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 X.X.X.X '/bin/sh -c '"'"'sudo -H -S -p "[sudo via ansible, key=hvgwnsbxpkxvbcmtcfvvvsplfphdrevxg] 密码:" -u jboss /bin/ sh -c '"'"'"'"'"'"'"'"'echo 成为成功-hvgwnsbxpkxvbcmtcfvvsplfphdrevxg; /usr/bin/python /tmp/ansible-tmp-XXXXXXXXX.XX-XXXXXXXXXXXXXX/command.py'"'"'"'"'"'"'"'"' && sleep 0'"'"''

【问题讨论】:

    标签: ansible ansible-playbook jboss5.x


    【解决方案1】:

    Ansible“命令”中不允许使用 &。

    command: sh /usr/jboss/bin/run.sh -c XXXXXXXX -b x.x.x.x &
    

    尝试删除它或使用 shell 代替命令。

    来自Ansible documentation about command

    给定的命令 [...] 不会 通过 shell 处理,所以像 $HOME 和操作这样的变量 像“”、“|”、“;”并且“&”将不起作用(如果 您需要这些功能)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-15
      • 1970-01-01
      • 2019-05-06
      • 1970-01-01
      • 2011-01-30
      相关资源
      最近更新 更多