Reputation: 2084
I have the following 2 tasks in a playbook:
- 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"
Do I have to register the variable and check it, or is it possible to combine them as 1 task? Something like:
- 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"
Upvotes: 1
Views: 111
Reputation: 68064
No. It's not possible. Module wait_for will do the job in one task.
- wait_for:
port: 22
host: 10.1.0.51
timeout: 3
msg: SSH is not running. End of play.
Upvotes: 1