Ansible
Key-terms
- role
- Jinja2/ template (.j2) = offering dynamic vars and facts
- Facts = vars that related to remote systems, OS, IP, attached file systems
- Magic vars = vars about ansible itself (?)
- Public Cloud (e.g. Amazon, Azure)
- Private Cloud (e.g. VMAre)
Udemy - Intro to Ansible
Objectives
- Intro to Ansible
- Ansible Configs
- Ansible Inventory
- Ansible Facts and vars
- Ansible playbook (all .yaml)
- Ansible Modules and plugins
- Ansible handlers
- Ansible Templates
- Reusing ansible content
Section 1: Intro to Ansible
- Ansible takes away repetitive tasks & long boring commands. As it helps with the following
- Resource Provision (migration, applying patches, sizing, creating new hosts, compliance, security audits)
- Config management
- CD
- App Deployment
- Security Compliance
Note: Ansible works on DB servers, other boxes, cloud web servers, localhost!
- Ansible = IT automation tool made simple, powerful and agentless (unlike chef, salt & puppet)
- Ansible real use case examples:
- e.g. 1: Shutting down web server then shut down DB, turn on DB first, turn on Web server last
- e.g. 2: Setting up infra on both public + private clouds (on-prem), hundreds of VMs then set up connections between the apps between public and private (+config, setting up firewall rules, …)
- Ansible built in modules support use cases such as e.g. 1 and e.g. 2
- Ansible can pull live statuses…such as the following:
- Data from CMDB to get list of target VMs
- Trigger config when SNOW tickets gets approved
Go check ansible documentation
- Ansible labs will be on KodeKloud
Section 2: Ansible config files
- Logics in ansible
- Ansible will always look for a config file, default look up location is
/etc/ansible/ansible.cfg
- Ansible config file governs and controls the default behavior using a set of params
- For introduction, here are 7 common Ansible section types
[defaults]
= locations to modules (libs), roles, logs, plugins…- Example
[defaults] inventory = /etc/ansible/hosts log_path = /var/log/ansible.log library = /usr/share/my_modules/ roles_path = /etc/ansible/roles action_plugins = /usr/share/ansible/plugins/action gathering = implicit # Whether Ansible should be gathering facts as default. Implicit is yes, explicit is no timeout = 10 # How long before giving up an ssh connection forks = 5 # How many hosts should ansible target when executing playbooks
- Example
[inventory]
= can enable certain inventory plugins, rest will discuss later- Example
[inventory]
- Example
[privilage_esclation]
[paramiko_connection]
[ssh_connection]
[persistent_connection]
[colors]
- Ansible will always look for a config file, default look up location is