what is ansible
Ansible is an open-source configuration management and automation tool that helps to streamline the process of deploying, configuring, and managing software applications and IT infrastructure.
With Ansible, you can automate tasks such as software deployment, server configuration, and application management. It uses a simple and easy-to-read language called YAML (Yet Another Markup Language) to describe automation tasks in the form of Ansible Playbooks.
One of the key advantages of Ansible is its agentless architecture, which means that it does not require any additional software to be installed on the remote hosts. Instead, Ansible uses SSH (Secure Shell) to connect to the remote hosts and execute tasks. This makes Ansible easy to set up and use, even in complex environments.
Ansible also provides a rich set of modules for performing a wide variety of tasks, including package installation, file management, and network configuration. It has a large and active community that provides support and contributes to the development of new features and modules.
ansible master and node configuration
To configure Ansible master and node, you need to follow these steps:
Install Ansible: First, you need to install Ansible on your master and nodes. You can install Ansible using your operating system's package manager or by downloading it from the Ansible website.
Configure SSH: Ansible uses SSH to connect to remote nodes. You need to configure SSH access between the master and nodes by creating SSH keys and adding them to the authorized_keys file on the nodes.
Set up inventory: Inventory is a file that contains a list of nodes that Ansible will manage. You need to create an inventory file on the Ansible master that contains the IP addresses or hostnames of the nodes that you want to manage.
Test connection: Once you have configured SSH and set up inventory, you can test the connection between the Ansible master and nodes by running the "ping" module. This module will send a ping command to the nodes and verify that they are accessible.
Write playbooks: Playbooks are YAML files that contain a list of tasks to be executed on the nodes. You can write playbooks to install packages, configure servers, and perform other tasks on the nodes.
Execute playbooks: You can execute playbooks on the nodes using the "ansible-playbook" command. This command will run the tasks specified in the playbook on the nodes.
Overall, configuring Ansible master and nodes involves setting up SSH, creating an inventory file, writing playbooks, and executing them on the nodes.
Launch 3 instances on AWS , 2 ubuntu 1 amz-linux
Login into those instances
# sudo apt update -y # sudo yum update -y
Now setup the hostname for all server.
$ sudo vi /etc/hostname ex: ubuntu-server
now configure DNS entries in each server
# sudo vi /etc/hosts example 172.31.33.240 ansible-control 172.31.42.23 ubuntu 172.31.33.6 centos save & exit
install ansible into your control machine
sudo apt update sudo apt install software-properties-common sudo apt-add-repository --yes --update ppa:ansible/ansible sudo apt install ansible -y
Create a common user in all server and assign sudo privileges
sudo adduser ansadm # ubuntu server sudo useradd ansadm # azm-linux machine sudo passwd ansadm # amz-linux machine
sudo visudo ## Allow root to run any commands anywhere root ALL=(ALL) ALL ansadm ALL=(ALL) NOPASSWD:ALL save & exit
Make sure PasswordAuthentication is yes
vi /etc/ssh/sshd_config PasswordAuthentication yes save and exit $ sudo systemctl restart ssh (ubuntu) $ sudo systemctl restart sshd (centos) $ sudo systemctl enable sshd
On ansible control-machine
su - ansadm # generate ssh key by running below command ssh-keygen cd .ssh ssh-copy-id ansadm@ubuntu ssh-copy-id ansadm@centos
Note: Default configuration of ansible is /etc/ansible/ansible.cfg default inventory file is /etc/ansible/hosts
Edit the ansible hosts file n update your node entries
$ sudo vi /etc/ansible/hosts example #192.168.0.1 #test.com centos ubuntu save & exit.
Check the connectivity from the ansible control machine to your node machine
ansible -m ping all
Did you find this article valuable?
Support Naveen Elwaka by becoming a sponsor. Any amount is appreciated!