Sobes.tech
Junior

How actively have you had to write roles and playbooks in Ansible for configuration?

sobes.tech AI

Answer from AI

Quite active. The main task was to ensure uniform server configuration and automate application deployment.

Both ready-made roles from Ansible Galaxy and custom-developed ones tailored to project needs were used. Playbooks were employed for task orchestration, dependency management between roles, and defining execution order.

Examples of tasks solved with Ansible:

  • Installing and configuring web servers (NGINX, Apache).
  • Configuring databases (PostgreSQL, MySQL).
  • Deploying microservices.
  • Managing users and groups.
  • Setting up firewalls.
  • Managing packages and dependencies.
  • Building and distributing application distributions.

When writing roles and playbooks, the following were actively used:

  • Jinja2 template system for dynamic generation of configuration files.
  • Handlers for executing actions after configuration changes.
  • Variables (group_vars, host_vars) for managing specific parameters.
  • Lookup plugins for retrieving information from various sources.
  • Conditionals for executing tasks based on conditions.

An example of a simple role structure:

// handlers/main.yml
---
# handlers file for my_role

// tasks/main.yml
---
# tasks file for my_role

An example of a simple playbook:

// playbook.yml
---
- name: Configure web server
  hosts: webservers
  become: yes # Execute tasks with superuser privileges
  roles:
    - my_web_server_role

Worked in conjunction with version control systems for pull requests and code review of Ansible. Tools for testing roles, such as Molecule, were also used.

Ansible Component Usage
Roles Organizing and reusing code
Playbooks Task and role orchestration
Variables Declarative configuration management
Handlers Responding to changes
Jinja2 Templates Dynamic file generation