Junior
What components and files does a role in DevOps consist of?
sobes.tech AI
Answer from AI
The role in DevOps, most often implemented through Ansible, consists of the following main components and files:
tasks/: Directory containing tasks executed by the role. The main file ismain.yml.// tasks/main.yml - name: Install nginx apt: name: nginx state: presenthandlers/: Directory containing event handlers. The main file ismain.yml. Handlers are executed only when there is a change in the tasks that notify them.// handlers/main.yml - name: restart nginx service: name: nginx state: restarteddefaults/: Directory containing default variable values for the role. The main file ismain.yml. These variables have the lowest priority.// defaults/main.yml nginx_port: 80vars/: Directory containing role-specific variables. The main file ismain.yml. These variables have a higher priority than those indefaults/.// vars/main.yml nginx_user: www-datafiles/: Directory containing files that will be copied to target machines without changes.// tasks/main.yml - name: Copy static file copy: src: my_static_file.conf dest: /etc/nginx/conf.d/my_static_file.conftemplates/: Directory containing template files (usually in Jinja2 format) that will be copied to target machines after processing (variable substitution).// templates/nginx.conf.j2 server { listen {{ nginx_port }}; ... }// tasks/main.yml - name: Configure nginx template: src: nginx.conf.j2 dest: /etc/nginx/nginx.conf notify: restart nginxmeta/: Directory containing role metadata, such as dependencies. The main file ismain.yml.// meta/main.yml dependencies: - role: another_role variable: valuelibrary/: (Optional) Directory for custom Ansible modules.module_utils/: (Optional) Directory for custom utility scripts used in modules.lookup_plugins/,filter_plugins/, etc.: (Optional) Directories for custom plugins of various types.
A typical role structure looks like this:
my_role/
├── tasks/
│ └── main.yml
├── handlers/
│ └── main.yml
├── defaults/
│ └── main.yml
├── vars/
│ └── main.yml
├── files/
│ └── my_static_file.conf
├── templates/
│ └── nginx.conf.j2
└── meta/
└── main.yml
These components allow organizing automation of installation, configuration, and management of services and systems in a structured and reusable way.