ansible run a task always at the end 1

ansible run a task always at the end

# Use block and always, which executes its tasks no matter what happens
# in the block tasks.
- name: Always do X
   block:
     - debug:
         msg: 'I execute normally'
     - name: i force a failure
       command: /bin/false
     - debug:
         msg: 'I never execute :-('
   always:
     - debug:
         msg: "This always executes, :-)"

Here is what the above code is Doing:
1. The first task is a debug task that prints a message.
2. The second task is a command task that forces a failure.
3. The third task is a debug task that prints a message.
4. The fourth task is a debug task that prints a message.

The first task executes normally. The second task fails. The third task
does not execute. The fourth task executes.

The always keyword is used to execute tasks no matter what happens in the
block tasks.

Similar Posts