Ansible
What is Ansible?
Ansible is an open source IT automation engine that automates
provisioning
configuration management
application deployment
orchestration
and many other IT processes. It is free to use, and the project benefits from the experience and intelligence of its thousands of contribution.
How Ansible works?
Ansible is agentless-doesn't need any software on the manage nodes.
For automating Windows and Linux, ansible connects to managed nodes and pushes out small programs called Ansible modules. Ansible executes these modules and removes them when finished.
For devices where modules can't be executed, it runs on the control node.
Passwordless Authentication:
ssh-copy-id -f "-o IdentityFile path" ubuntu@public-ip
What is the difference between Ansible ad-hoc commands and playbooks?
Adhoc commands-for one or two tasks
Playbooks-for multiple commands.
Here are the steps for the above project:
Step1:Create one control node and 2 managed nodes
Step2:Set the passwordless authentication for both the manged nodes using the above command
ssh-copy-id -f "-o IdentityFile " ubuntu@publicip
or ssh -i path ubuntu@publicip
or using password :
Go to the file
/etc/ssh/sshd_config.d/60-cloudimg-settings.conf
Update
PasswordAuthentication yes
Restart SSH ->
sudo systemctl restart ssh
Step3:
Create the inventory file and add their ipaddress
Step4:
Check if we can ping the webserver in the inventory file.
ansible -i inventory.ini -m ping all
Step5:
Write a playbook and run the above command.
name: Install and start Nginx
hosts: webservers
become: yes
tasks:
-name: Ensure Nginx is installed
apt:
name: nginx
state: present
update_cache: yes
-name: Ensure Nginx is started
service: name: nginx
state: started
enabled: yes
ansible-playbook -i inventory.ini firstplaybook.yml