Configuration
Configuration blocks manage the configuration and setup of your infrastructure resources. Utilizing a playbook-like structure to define tasks that configure servers, install software, manage services, and perform other configuration-related activities.
Syntax
Defining Plays
A play groups a set of tasks that are executed against specified hosts. It can include variables, become (privilege escalation), and handlers.
Attributes:
name: A descriptive name for the play.
hosts: Specifies the target hosts (e.g., all, specific groups).
become: Determines if privilege escalation is required.
vars: Defines variables to be used within the play.
Tasks
Tasks define individual actions to configure the system. They use modules to perform specific operations like installing packages, copying files, managing services, etc.
Common Modules:
package: Manages software packages.
copy: Copies files to the target system.
service: Manages system services.
shell/command: Executes shell commands.
Attributes:
name: A descriptive name for the task.
module-specific attributes: Vary based on the module used.
when: Conditional execution based on system facts.
loop: Iterates over a list of items.
register: Captures the output of a task.
notify: Triggers handlers upon task completion.
retries/delay: Configures retry behavior.
Handlers
Handlers are special tasks that are triggered by notifications from other tasks. They are typically used to restart or reload services after configuration changes.
Attributes:
name: A descriptive name for the handler.
module-specific attributes: Define the action the handler performs.
Conditionals and Loops
when: Executes tasks based on specific conditions (e.g., OS type).
loop: Repeats tasks for each item in a list.
Example
Last updated