Installation and Configuration
Installation and Configuration
Installing Ansible
Package Manager Installation
- Using pip (recommended)
python3 -m pip install --user ansible
- Using apt (Ubuntu/Debian)
sudo apt update sudo apt install ansible
- Using yum (RHEL/CentOS)
sudo yum install ansible
Verifying Installation
- Check Ansible version
ansible --version
- Verify Python environment
- Review installed collections
Configuring SSH Access
SSH Key Setup
- Generate SSH key pair
ssh-keygen -t rsa -b 4096
- Copy public key to managed nodes
ssh-copy-id username@target_host
- Test SSH connection
ssh username@target_host
SSH Configuration Best Practices
- Use SSH config file
- Set up key-based authentication
- Configure connection timeouts
- Enable connection multiplexing
Basic Configuration Files
ansible.cfg
- Default configuration file
- Common settings:
[defaults] inventory = ./inventory remote_user = ansible host_key_checking = False
Inventory File
- Basic inventory structure:
[webservers] web1.example.com web2.example.com [dbservers] db1.example.com db2.example.com
Configuration Hierarchy
- Command line options
- Environment variables
- ansible.cfg file
- Default settings
Practical Exercise
Basic Setup
- Create project directory
- Initialize ansible.cfg
- Create inventory file
- Test connectivity
First Ansible Command
ansible all -m ping
Common Issues and Solutions
- SSH connection problems
- Python interpreter issues
- Permission problems
- Inventory configuration
Key Takeaways
- Multiple installation methods available
- SSH configuration is crucial
- Configuration files provide flexibility
- Start with basic setup and expand