This repository is a collection of Ansible Playbooks and Roles designed to automate common tasks across various IT infrastructure components, including Linux servers, cloud environments, and potentially network devices.
Ansible is an open-source automation platform that simplifies configuration management, application deployment, and task automation without needing agents on the target machines (agentless).
This repository aims to cover several common automation scenarios (Playbooks will be structured accordingly):
- Configuration Management: Ensuring consistency across all managed hosts (e.g., standardizing SSH settings, managing user accounts, and deploying configuration files).
- Application Deployment: Automating the installation and deployment of applications (e.g., web servers like Nginx/Apache, database systems, or custom application code).
- System Provisioning: Automating the setup of new virtual machines or servers (installing required packages, setting up firewall rules, and configuring basic OS settings).
- Network Automation (Optional): If network playbooks are included, they would handle tasks like configuration backups, compliance checks, or interface configuration on devices like Cisco, Juniper, or Fortinet.
Ansible projects follow a standard directory layout. A typical structure for this repository might look like this:
Ansible/
├── inventory/
│ ├── production # Inventory file for production hosts
│ └── staging # Inventory file for staging/testing hosts
├── playbooks/
│ ├── site.yml # Main entry point playbook
│ ├── web_deployment.yml
│ └── system_hardening.yml
├── roles/
│ ├── webserver/ # Role for configuring web servers
│ │ ├── tasks/
│ │ └── handlers/
│ └── security/ # Role for applying security baseline
│ ├── tasks/
│ └── vars/
├── group_vars/
│ ├── webservers.yml # Variables specific to the 'webservers' group
│ └── all.yml # Variables applicable to all hosts
└── README.md
inventory/: Defines the list of managed nodes (servers, devices) and groups them logically.playbooks/: Contains the main YAML files (.yml) that orchestrate tasks against the hosts defined in the inventory.roles/: Reusable and standardized units of automation, allowing for modular and clean Playbooks.group_vars/: Stores variables specific to host groups (e.g., common ports, version numbers, credentials).
- Ansible Control Node: A machine (usually Linux) with Ansible installed.
pip install ansible
- Managed Hosts: Remote machines accessible via SSH, with Python installed (for Linux servers).
- Define Inventory: Ensure your target hosts are correctly listed in the
inventory/file (e.g.,productionorstaging). - Execute: Run a playbook using the
ansible-playbookcommand, specifying the path to your playbook and the inventory file.
Example: Running the main deployment playbook against the production inventory:
ansible-playbook -i inventory/production playbooks/site.ymlFor quick checks or single tasks across your inventory:
# Ping all hosts defined in the inventory
ansible all -i inventory/production -m ping
# Check the uptime of web servers
ansible webservers -i inventory/production -m command -a "uptime"Feel free to fork this repository, add new roles, improve existing playbooks, or report issues. Contributions help keep this automation collection robust and up-to-date.