Cloud Computing & IaC in DevOps (Ansible)

Cloud Computing & IaC in DevOps (Ansible)

?? What is Ansible? ??

Ansible is an open-source configuration management and automation tool developed by Red Hat. It helps you:

  • Automate software provisioning.
  • Manage configurations across servers.
  • Orchestrate complex deployment workflows.

Key Features:

  • Agentless: No need to install agents on target systems.
  • Simple YAML syntax: Configuration is defined in human-readable YAML files called playbooks.
  • Idempotent: Ensures that tasks are applied only if changes are needed.


?? Why Ansible in DevOps?

  1. Consistency: Apply the same configuration across multiple servers.
  2. Scalability: Manage hundreds or thousands of nodes with a single command.
  3. Integration: Works well with tools like Terraform, Jenkins, and Docker.


?? Real-World Analogy: Managing a Restaurant Chain ???

Imagine you manage a restaurant chain:

  • You need to ensure that all branches follow the same standards—menu, decor, service.
  • Ansible acts as your operations manager, sending clear, repeatable instructions to every branch.
  • If a new recipe (software update) is added, Ansible ensures every branch gets it correctly and consistently.


??? Installing Ansible

On Ubuntu/Linux: (bash)

sudo apt update
sudo apt install ansible -y        

On macOS:(bash)

brew install ansible        

Verify Installation:

ansible --version        

?? Basic Ansible Concepts

1. Inventory:

  • A list of managed nodes (servers).
  • Defined in an inventory file: (ini)

[webservers]
server1.example.com
server2.example.com        

2. Playbooks:

  • YAML files containing a set of tasks to be executed on target hosts.
  • Example playbook.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        

3. Modules:

  • Pre-built libraries in Ansible for automating tasks (e.g., apt, yum, copy, file).

4. Tasks:

  • Individual actions performed by Ansible (e.g., install a package, copy a file).


?? Running an Ansible Playbook

1. Create an Inventory File (inventory.ini):

[webservers]
192.168.1.10        

2. Run the Playbook:

ansible-playbook -i inventory.ini playbook.yaml        

??? Best Practices with Ansible ?

  1. Use Roles: Organize playbooks into reusable roles.
  2. Variables: Store dynamic values in separate files or vars sections.
  3. Vault: Encrypt sensitive data (passwords, keys) with Ansible Vault.
  4. Version Control: Store playbooks in Git repositories for collaboration and tracking changes.


?? Fun Fact

Did you know that NASA uses Ansible to automate the deployment of software across its servers? Ansible’s reliability and simplicity make it a trusted choice for mission-critical tasks!




Mouhssine RACHAD

Engineering | IT Specialist | IT Project | Administrator | Virtualisation | Cyber Security | SOC | Cloud ?? | Networking ?

3 个月

Very informative ??

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

Sahil Kasekar的更多文章

社区洞察