Ansible Tasks
Learn how to write Ansible tasks.
What are tasks?
A task represents a single action within a playbook that we can perform on a managed node. Tasks make up plays and leverage modules to perform specific actions like installing software, copying files, managing users, etc.
In order to define a task, we have to specify a name, the module we’d like to use, and other relevant parameters. Here’s the basic syntax for defining a task:
In the syntax above, a task contains the following parameters:
name: Describes the task in a human-readable manner, e.g., “Installing NGINX.”module_name: Used to specify the Ansible module to be used in the task in order to achieve the specific actionmodule_parameter: The arguments that we need to pass to the module that we choose for our task.
A working example of a task is shown below:
-
Line 2: The task uses the
commandmodule within an Ansible playbook to execute thenginx -tcommand on a managed node. This command is typically used to perform a configuration test for the NGINX web server and check ...