Introduction to Ansible
•Open-source automation tool by Red Hat
• Agentless - uses SSH
• Uses YAML for configuration
• Comparison: Puppet, Chef, SaltStack
3.
How Ansible Works
•Control Node and Managed Nodes
• Inventory file defines hosts
• Modules execute tasks
• Plugins extend functionality
• Playbooks define automation steps
4.
Setting Up Ansible
•Install using package managers
• Create inventory file
• Verify connection with ping module
5.
Ad-hoc Commands
• One-linertasks without playbooks
• Examples: ping, shell, yum, service
• Useful for quick checks or tasks
6.
Playbooks
• Written inYAML
• Define hosts, tasks, variables, handlers
• Idempotent and readable
7.
Roles
• Organize playbooksinto reusable parts
• Structure: tasks/, vars/, handlers/, templates/
• Use with 'ansible-galaxy init'
8.
Templates and Jinja2
•Dynamic configuration using variables
• Jinja2 syntax for conditions, loops
• Used with template module
9.
Error Handling andDebugging
• Use ignore_errors and failed_when
• Register outputs, debug info
• Verbose output with -v/-vvv
• Dry-run with --check
10.
Best Practices
• Useconsistent structure and roles
• Encrypt secrets with Vault
• Test in staging environment
• Write idempotent tasks
11.
Ansible Vault
• Encryptsecrets like passwords and keys
• Create encrypted files with ansible-vault
• Use --ask-vault-pass when running playbooks