12-Day5-3-roles
Day 5: Lab Series 2 - Introduction to Roles and Their Directory Structure
Lab 2.1: Creating a Basic Role
ansible-galaxy init ~/day5/roles/webserver~/day5/roles/webserver/ ├── defaults/ ├── files/ ├── handlers/ ├── meta/ ├── tasks/ ├── templates/ ├── tests/ └── vars/--- - name: Install Apache yum: name: httpd state: present - name: Start and enable Apache service: name: httpd state: started enabled: true--- web_port: 80--- - name: Restart Apache service: name: httpd state: restarted<html> <head> <title>Welcome to {{ inventory_hostname }}</title> </head> <body> <h1>Apache is running on {{ ansible_facts['os_family'] }}!</h1> </body> </html>--- - name: Install Apache yum: name: httpd state: present - name: Deploy web page template: src: index.html.j2 dest: /var/www/html/index.html mode: '0644' - name: Start and enable Apache service: name: httpd state: started enabled: true--- - name: Deploy Web Server hosts: webservers roles: - role: webserveransible-playbook ~/day5/webserver_role_playbook.yaml -i inventory
Lab 2.2: Adding Role Variables
Lab 2.3: Using Multiple Roles in a Single Playbook
Optional Lab: Debugging and Troubleshooting Roles
Key Learning Points:
Previous12-Day5-1-include_tasksAndimport_tasksNext14-Day5-3-UnderstandingAndConfiguringExecutionStrategies
Last updated