Ansible
- Ansible can communicate with nodes by using two approaches
- adhoc commands:
- We build a command for desired state
- playbook:
- We create a file where we express desired state
- This is recommended approach for repetitive activites
- adhoc commands:
Playbook
- We have taken a sample playbook
---
- name: hello ansible
hosts: all
become: yes
tasks:
- name: update packages and install tree
apt:
name: tree
state: present
update_cache: yes
- We executed playbook
- Basic Playbook semantics
- In ansible the smallest unit of work is perfomed by module
YAML
- YAML vs JSON
- Refer Here for yaml syntax from ansible
Ways of Working (WoW):
- list down all the manual steps
- Ensure all the steps are working
- For each step find a module and express the desired state
Activity 1: Install apache server
- Manual steps
sudo apt update
sudo apt install apache2 -y
- Verify the installation
http://<public-ip>
- Refer Here for ansible yaml syntax for playbook
- Finding the module:
- search google with
<command> in ansible
- search from ansible docs Refer Here
- search google with
- all the commands for installation are executed with sudo
---
- name: install apache server
hosts: all
become: yes
tasks:
- name: install apache
ansible.builtin.apt:
name: apache2
update_cache: yes
state: present
- create inventory
172.31.27.136
- Run the command
ansible-playbook -i <inventory-path> <playbook-path>
- Execute the playbook
- verify the apache