Junior — Middle
How is automation of configuration and infrastructure management implemented with Ansible?
sobes.tech AI
Answer from AI
Ansible is a tool for automation of configuration and infrastructure management that uses a declarative approach and SSH for interacting with remote servers.
Automation with Ansible is implemented through:
- Playbooks — YAML files describing the desired state of the system (installing packages, configuring services, copying files, etc.).
- Modules — built-in or custom scripts that perform specific tasks (for example, the
aptmodule for installing packages on Debian/Ubuntu). - Inventory — a list of managed hosts grouped by roles or environments.
An example of a simple playbook for installing and starting nginx:
- hosts: webservers
become: yes
tasks:
- name: Install nginx
apt:
name: nginx
state: present
update_cache: yes
- name: Start and enable nginx
service:
name: nginx
state: started
enabled: yes
The playbook is run with the command:
ansible-playbook -i inventory.ini playbook.yml
Thus, Ansible allows describing infrastructure as code, which facilitates repeatability, scalability, and change control.