'How to stop Ansible task cleanly (without failing) and move on to next task?

I'm automating the process of starting eNodeB and then attaching a UE to it.

Here is the connection diagram Connection diagram

I have created a nested playbook which consists for various playbooks for both VMs.

When I run the playbook for starting the eNodeB, the task runs perfectly fine, even the eNodeB is starting but the task is stuck and won't get till the play recap. Task is stuck

I want to stop eNodeB task cleanly (without failing error) and move on to next task of attaching UE. Can this be done?

I tried adding a timeout to the task, but it gives a fatal error and hence attaching UE task can't be run.

PS: When I start the eNodeB manually, like demonstrated below, it waits to display packet trace information. I used to open a new window to run command of attaching UE.

Starting the eNodeB manually



Solution 1:[1]

What you could do is to run that task of starting the eNodeB as an asynchronous action, and then poll it until you find an indication that it is indeed running in the return of it.

In your screenshot, it seems like the node outputting ==== eNodeB started === is a clear indication that it is up and running and that you could move forward.

Here would be an example, in two tasks:

## I am using a command here to simulate what you are having
## but any Ansible task would do, you just have to mimic
## the register, async and poll parameters for it to work
- command: ./startup.sh
  async: 1000
  poll: 0
  register: cmd

- async_status:
    jid: "{{ cmd.ansible_job_id }}"
  register: job_result
  until: "'==== eNodeB started ===' in job_result.stdout"
  ## ^-- mind that, based on the exact task you are using 
  ## it could be something else dans the stdout property 
  ## you have to asses
  retries: 100
  delay: 1

Given the test script startup.sh

#!/usr/bin/env sh

sleep 10
echo "==== eNodeB started ==="

And those there tasks:

- command: ./startup.sh
  async: 1000
  poll: 0
  register: cmd

- async_status:
    jid: "{{ cmd.ansible_job_id }}"
  register: job_result
  until: "'==== eNodeB started ===' in job_result.stdout"
  retries: 100
  delay: 1

- debug:
    msg: Going forward now

This yields:

TASK [command] ***************************************************************
changed: [localhost]

TASK [async_status] **********************************************************
FAILED - RETRYING: [localhost]: async_status (100 retries left).
FAILED - RETRYING: [localhost]: async_status (99 retries left).
FAILED - RETRYING: [localhost]: async_status (98 retries left).
FAILED - RETRYING: [localhost]: async_status (97 retries left).
FAILED - RETRYING: [localhost]: async_status (96 retries left).
FAILED - RETRYING: [localhost]: async_status (95 retries left).
FAILED - RETRYING: [localhost]: async_status (94 retries left).
FAILED - RETRYING: [localhost]: async_status (93 retries left).
changed: [localhost]

TASK [debug] *****************************************************************
ok: [localhost] => 
  msg: Going forward now

Solution 2:[2]

Synchronization with an async task didn't worked. But running Asynchronous playbook tasks concurrently (with poll = 0) works fine.

- name: Start eNodeB
  command: enodeb_startup_commnd
  async: 1000
  poll: 0

- debug:
  msg: eNodeB started

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Harshal