In this blog post, we introduce you to a selection of Ansible modules that allow you to trigger very specific (mostly internal) actions.
- name: Quit play
meta: end_play
The number of available meta-actions has grown steadily over the years. Ansible 2.12 and later know the following nine actions:
- debug: msg="Hello"
- debug: var=ansible_default_ipv4
The naming of these tasks with name is often omitted, if only because a debug task often should not remain in the play. Using the var parameter helps when you want to show the contents of a variable easily.
The online documentation for this is found here.
- set_fact:
hour: ""
- fail:
msg: "It is simply too late today."
when: hour|int > 20
With the fail module, you can deliberately trigger a failure and thus end the play for the respective hosts. In the old days of Ansible, before meta: end_play was invented, this was the only way to exit a play.
The online documentation for this is here.
- pause:
prompt: Please turn off the lights now
- name: Give the CPU time to cool down
pause:
seconds: 30
- pause:
prompt: Please enter your name
register: this
- debug: msg="Goodbye !"
With the pause module, you can stop the execution of a playbook for a period of time.
Attention: Please do not use pause to wait for interactive input if your playbook might run in noninteractive environments like Cron or Ansible AWX/Tower!
The online documentation for this is at this link.
- name: Wait until the file /tmp/foo is present
wait_for:
path: /tmp/foo
- name: Wait 300 seconds for port 8000 to become open
wait_for:
port: 8000
With the wait_for module, you can wait in the play until a certain condition is met. The maximum wait time is 300 seconds by default (with the timeout parameter). In addition to the possibilities shown here, you can wait for a port to close or you can compare file contents or sockets with a regular expression and wait until the pattern matches. The online documentation for this is found here.
- name: Wait 600 seconds for target connection to become reachable/usable
wait_for_connection:
timeout: 600
The timeout of 600 seconds is the default and therefore does not need to be specified separately.
The online documentation for this is here.
- name: It must be Debian 9 or 10
assert:
that:
- ansible_distribution == "Debian"
- ansible_distribution_major_version is version('9', '>=')
- ansible_distribution_major_version is version('10', '<=')
fail_msg: "Only Debian version 9 or 10 is supported"
The assert module ensures that all specified conditions are met; otherwise, processing is aborted with an error. The online documentation for this is at this link.
- name: Set two variables
set_fact:
foo: 100
bar: 200
- debug: msg="foo = , bar = "
With set_fact, you can set host-specific variables at runtime.
The online documentation for this is at this link.
Editor’s note: This post has been adapted from a section of the book Ansible: The Practical Guide for Administrators and DevOps Teams by Axel Miesen. Axel is an Ansible coach. His interest in Linux systems began with his studies at the University of Kaiserslautern, where he studied mathematics and computer science. After graduating in 1998, he began working as a consultant and trainer and has passed on his Linux knowledge and experience to numerous professionals.
This post was originally published 8/2025.