剧本中的这些Ansible任务可以以某种方式合并为一项任务吗?

时间:2019-07-18 03:45:34

标签: ansible

我在剧本中有以下两个任务:

  - name: Check if SSH is running on port 22
    shell: netstat -tunlp | grep ":22 " | sed -e 's/.*\///' | sort -u
    register: ssh_running

  - name: Exit if SSH is not running
    meta: end_play
    when: ssh_running.stdout | trim | lower != "sshd"

我必须注册并检查变量,还是可以将它们合并为1个任务?像这样:

  - name: Check if SSH is running on port 22
    shell: netstat -tunlp | grep ":22 " | sed -e 's/.*\///' | sort -u
    meta: end_play
    when: output_of_shell_command | trim | lower != "sshd"

1 个答案:

答案 0 :(得分:1)

不。这是不可能的。模块wait_for将完成一项任务。

- wait_for:
    port: 22
    host: 10.1.0.51
    timeout: 3
    msg: SSH is not running. End of play.