This repository contains Ansible playbooks and roles for automating infrastructure configuration and management tasks across multiple servers.
This project provides a comprehensive Ansible automation solution for managing web and database servers. It includes playbooks for system updates, package management, and service configuration across different Linux distributions (CentOS, RedHat, Ubuntu, Debian).
ansible/
├── ansible.cfg # Ansible configuration file
├── hosts # Inventory file defining target hosts
├── group_vars/ # Group-specific variables
├── playbook.yml # Main playbook for running updates
├── playbook2.yml # Nginx installation and management
├── playbook3.yml # Package removal and installation
├── roles/ # Ansible roles
│ ├── common/ # Common tasks for all servers
│ │ ├── handlers/
│ │ ├── meta/
│ │ └── tasks/
│ ├── php/ # PHP installation role
│ │ ├── handlers/
│ │ └── tasks/
│ └── updates/ # System update role
│ ├── handlers/
│ └── tasks/
└── vagrant_ubuntu_*/ # Vagrant configurations
- Ansible 2.9 or higher
- SSH access to target hosts
- Python installed on target hosts
- Sudo privileges on target hosts
The hosts file defines the target servers:
- Web Servers (
servidores_web): 192.168.33.10 - Database Servers (
servidores_db): 192.168.33.11
Key settings in ansible.cfg:
- Default user:
vagrant - SSH port: 22
- Privilege escalation: sudo to root
- Host key checking: disabled (for development)
Runs system updates across all hosts using the updates role.
ansible-playbook playbook.ymlInstalls and configures Nginx on web servers.
ansible-playbook playbook2.ymlFeatures:
- Installs latest Nginx version
- Includes handlers for service management
- Targets only web servers group
Manages package installation and removal on web servers.
ansible-playbook playbook3.ymlManages packages:
- Removes: nginx, httpd (if present)
- Installs: nmap, nginx, vim, tcpdump
General server configuration tasks:
- System package updates (yum-based systems)
- Essential tools installation (net-tools, nano, nmap)
- Timezone configuration (America/Sao_Paulo)
- File backup and template deployment
- Nginx installation (for Debian-based systems)
Cross-platform system updates:
- Red Hat/CentOS: Security updates via yum
- Debian/Ubuntu: Full system upgrade via apt
- Automatically detects distribution and applies appropriate update method
Simple PHP5 installation for web servers (Debian-based systems).
ansible-playbook -i hosts playbook.ymlansible-playbook -i hosts playbook2.ymlansible-playbook -i hosts playbook.yml --limit servidores_webansible-playbook --syntax-check playbook.ymlansible-playbook -i hosts playbook.yml --checkThis project includes Vagrant configurations for local testing:
vagrant_ubuntu_01/: Ubuntu test environmentvagrant_ubuntu_02/: Additional Ubuntu test environment
To start the Vagrant environments:
cd vagrant_ubuntu_01
vagrant up- SSH keys are used for authentication (no password prompts)
- Privilege escalation is configured for sudo operations
- Consider enabling host key checking in production
- Review and customize the
ansible.cfgfor production use
- Always test playbooks in development before production
- Use
--checkmode to preview changes - Keep sensitive data in encrypted vault files
- Use version control for all playbook changes
- Document any custom modifications to roles
- Connection refused: Verify SSH access and host availability
- Permission denied: Check sudo configuration on target hosts
- Package not found: Ensure repository configuration is correct
- Handler not found: Verify handler names match between tasks and handlers
Run playbooks with increased verbosity:
ansible-playbook -i hosts playbook.yml -vvv- Fork the repository
- Create a feature branch
- Test your changes thoroughly
- Submit a pull request with clear description
This project is licensed under the terms included in the LICENSE file.
For issues, questions, or suggestions, please open an issue in the repository.