Search for a command to run...
Complete guide for installing and setting up Ansible, an agentless automation tool that enables infrastructure as code, configuration management, and application deployment using simple YAML syntax.
Ansible is an open-source automation tool that enables infrastructure as code, configuration management, application deployment, and task automation. It uses a simple, human-readable language (YAML) and requires no agents on remote systems.
# Create Ansible directory structure
mkdir -p ~/ansible/playbooks
cd ~/ansible
Create inventory.ini
:
[webservers]
web1 ansible_host=192.168.1.10
web2 ansible_host=192.168.1.11
[dbservers]
db1 ansible_host=192.168.1.20
[all:vars]
ansible_user=your_ssh_user
ansible_ssh_private_key_file=~/.ssh/id_rsa
Create ansible.cfg
:
[defaults]
inventory = ./inventory.ini
remote_user = your_ssh_user
private_key_file = ~/.ssh/id_rsa
host_key_checking = False
# Ping all hosts
ansible all -m ping
# Check specific group
ansible webservers -m ping
Create playbooks/update_servers.yml
:
---
- name: Update all servers
hosts: all
become: yes
tasks:
- name: Update apt cache (Debian/Ubuntu)
apt:
update_cache: yes
when: ansible_os_family == "Debian"
- name: Update dnf cache (RHEL/CentOS)
dnf:
update_cache: yes
when: ansible_os_family == "RedHat"
# Run playbook
ansible-playbook playbooks/update_servers.yml
# Run with extra variables
ansible-playbook playbooks/update_servers.yml -e "variable=value"
# Generate SSH key
ssh-keygen -t rsa -b 4096
# Copy key to remote hosts
ssh-copy-id username@remote_host
# Create encrypted file
ansible-vault create secrets.yml
# Edit encrypted file
ansible-vault edit secrets.yml
# Run playbook with vault
ansible-playbook playbook.yml --ask-vault-pass
# Create role structure
ansible-galaxy init my_role
# Role directory structure
my_role/
├── defaults/
├── files/
├── handlers/
├── meta/
├── tasks/
├── templates/
└── vars/
Project Organization
Security
Performance
SSH Connection Problems
# Check SSH connection
ssh -v username@remote_host
# Test Ansible connection
ansible host -m ping -vvv
Permission Issues
# Check sudo access
ansible host -m shell -a "sudo -l"
# Run with become
ansible-playbook playbook.yml --become
Python Issues
# Check Python version
ansible host -m setup -a "filter=ansible_python_version"
# Install Python if missing
ansible host -m raw -a "apt-get install -y python3"
Module Errors
Playbook Syntax
# Check playbook syntax
ansible-playbook --syntax-check playbook.yml
# Run in check mode
ansible-playbook --check playbook.yml
A comprehensive guide for installing and configuring HashiCorp Terraform, an Infrastructure as Code (IaC) tool for building, changing, and versioning infrastructure safely and efficiently.
Step-by-step guide for installing and configuring HashiCorp Vault, a secrets management tool that provides secure, centralized storage and access control for tokens, passwords, certificates, and encryption keys.