Cloud Computing & IaC in DevOps (Ansible Playbook)

Cloud Computing & IaC in DevOps (Ansible Playbook)

?? What is a Playbook? ??

An Ansible playbook is a YAML file that defines a set of tasks to run on target machines. It describes what to do, not how to do it, making infrastructure automation readable and easy to understand.


??? Your First Ansible Playbook: Installing Nginx

1. Create the Playbook File (nginx_install.yaml):

(yaml)

- name: Install and start Nginx  
  hosts: webservers  
  become: yes  # Run as root  

  tasks:  
    - name: Install Nginx  
      apt:  
        name: nginx  
        state: present  

    - name: Start Nginx service  
      service:  
        name: nginx  
        state: started          

2. Create the Inventory File (inventory.ini):

(ini)

[webservers]  
192.168.1.10          

3. Run the Playbook:

(bash)

ansible-playbook -i inventory.ini nginx_install.yaml          

?? What This Playbook Does:

  1. Defines the target servers in the webservers group.
  2. Installs Nginx using the apt module.
  3. Starts the Nginx service to ensure it’s running.


?? Key Benefits:

  • Consistency: Deploy the same configuration across multiple servers.
  • Automation: No more manual package installations.
  • Simplicity: Easy-to-read YAML syntax.



要查看或添加评论,请登录

Sahil Kasekar的更多文章

社区洞察

其他会员也浏览了