This directory contains Ansible configuration for managing CentOS 6, CentOS 7, and Ubuntu servers.
chmod +x 1.install.ansible.sh
./1.install.ansible.shGenerate 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-ipEdit inventory/hosts.ini and add your servers:
- Replace example IPs with your actual server IPs
- Add all 100+ servers in their respective groups
ansible all -m ping.
├── 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
ansible all -m pingansible-playbook playbooks/ping-all.yml
ansible-playbook playbooks/system-update.yml
ansible-playbook playbooks/gather-facts.yml
ansible-playbook playbooks/install-common-packages.yml# 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"ansible centos6 -m ping
ansible centos7 -m ping
ansible ubuntu -m ping
ansible centos -m ping # All CentOS serversEdit 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.30Add to inventory or group_vars:
[centos6]
server-01 ansible_host=192.168.1.10 ansible_user=admin ansible_port=2222# 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-passAlways use SSH keys instead of passwords. If you must use passwords temporarily:
ansible all -m ping --ask-pass- Use Groups: Organize servers by role, environment, or OS
- Parallel Execution: Adjust
forksin ansible.cfg (default: 20) - Fact Caching: Enabled by default to speed up playbooks
- Use Tags: Tag tasks for selective execution
- Dynamic Inventory: Consider using dynamic inventory for cloud providers
# Verbose output
ansible all -m ping -vvv
# Test SSH manually
ssh -i ~/.ssh/id_rsa root@server-ipCentOS 6 uses Python 2.7. The inventory is pre-configured with:
[centos6:vars]
ansible_python_interpreter=/usr/bin/python2.7ansible --version- Customize
group_vars/all.ymlwith your settings - Create custom roles in
roles/directory - Add more playbooks for your specific needs
- Set up a Git repository to version control your configs
- Consider using Ansible Tower/AWX for web UI management
- Ansible Documentation
- Ansible Galaxy - Pre-built roles
- Best Practices