Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Ansible Management for 100+ Servers

This directory contains Ansible configuration for managing CentOS 6, CentOS 7, and Ubuntu servers.

Quick Start

1. Install Ansible

chmod +x 1.install.ansible.sh
./1.install.ansible.sh

2. Setup SSH Keys

Generate SSH key if you don't have one:

ssh-keygen -t rsa -b 4096 -C "ansible@$(hostname)"

Copy SSH key to all servers:

ssh-copy-id root@server-ip

3. Configure Inventory

Edit inventory/hosts.ini and add your servers:

  • Replace example IPs with your actual server IPs
  • Add all 100+ servers in their respective groups

4. Test Connectivity

ansible all -m ping

Directory Structure

.
├── 1.install.ansible.sh       # Installation script
├── ansible.cfg                 # Ansible configuration
├── inventory/                  # Server inventory
│   └── hosts.ini              # Main inventory file
├── group_vars/                 # Variables for groups
│   ├── all.yml                # Variables for all servers
│   ├── centos6.yml            # CentOS 6 specific vars
│   ├── centos7.yml            # CentOS 7 specific vars
│   └── ubuntu.yml             # Ubuntu specific vars
├── host_vars/                  # Variables for specific hosts
├── playbooks/                  # Ansible playbooks
│   ├── ping-all.yml           # Test connectivity
│   ├── system-update.yml      # Update all servers
│   ├── gather-facts.yml       # Collect system info
│   ├── install-common-packages.yml
│   └── user-management.yml
├── roles/                      # Ansible roles
└── logs/                       # Ansible logs

Common Commands

Test connectivity

ansible all -m ping

Run playbooks

ansible-playbook playbooks/ping-all.yml
ansible-playbook playbooks/system-update.yml
ansible-playbook playbooks/gather-facts.yml
ansible-playbook playbooks/install-common-packages.yml

Ad-hoc commands

# Check uptime on all servers
ansible all -m command -a "uptime"

# Check disk space
ansible all -m shell -a "df -h"

# Restart a service
ansible centos7 -m service -a "name=httpd state=restarted"

# Run command on specific group
ansible centos6 -m command -a "cat /etc/redhat-release"

Target specific groups

ansible centos6 -m ping
ansible centos7 -m ping
ansible ubuntu -m ping
ansible centos -m ping  # All CentOS servers

Inventory Management

Adding Servers

Edit inventory/hosts.ini:

[centos6]
server-01 ansible_host=192.168.1.10
server-02 ansible_host=192.168.1.11

[centos7]
server-03 ansible_host=192.168.1.20

[ubuntu]
server-04 ansible_host=192.168.1.30

Using Different SSH Users

Add to inventory or group_vars:

[centos6]
server-01 ansible_host=192.168.1.10 ansible_user=admin ansible_port=2222

Security Best Practices

Use Ansible Vault for Sensitive Data

# Create encrypted file
ansible-vault create group_vars/all/vault.yml

# Edit encrypted file
ansible-vault edit group_vars/all/vault.yml

# Run playbook with vault
ansible-playbook playbooks/deploy.yml --ask-vault-pass

SSH Key Authentication

Always use SSH keys instead of passwords. If you must use passwords temporarily:

ansible all -m ping --ask-pass

Tips for Managing 100+ Servers

  1. Use Groups: Organize servers by role, environment, or OS
  2. Parallel Execution: Adjust forks in ansible.cfg (default: 20)
  3. Fact Caching: Enabled by default to speed up playbooks
  4. Use Tags: Tag tasks for selective execution
  5. Dynamic Inventory: Consider using dynamic inventory for cloud providers

Troubleshooting

Connection Issues

# Verbose output
ansible all -m ping -vvv

# Test SSH manually
ssh -i ~/.ssh/id_rsa root@server-ip

Python Issues on CentOS 6

CentOS 6 uses Python 2.7. The inventory is pre-configured with:

[centos6:vars]
ansible_python_interpreter=/usr/bin/python2.7

Check Ansible Version

ansible --version

Next Steps

  1. Customize group_vars/all.yml with your settings
  2. Create custom roles in roles/ directory
  3. Add more playbooks for your specific needs
  4. Set up a Git repository to version control your configs
  5. Consider using Ansible Tower/AWX for web UI management

Resources

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages