Skip to main content

Posts

Showing posts from May, 2017

Get information about remote hosts using Ansible

Get information about remote hosts using Ansible setup command Below command gives all the information of client hosts which includes memory, server architecture, IP adresses etc. [root@ansible mywork]# ansible all -i hosts -m setup If you need just memory information of remote node then for the above command need to add filter as shown below [root@ansible mywork]# ansible all -i hosts -m setup -a "filter=ansible_*_mb" node01 | SUCCESS => {     "ansible_facts": {         "ansible_memfree_mb": 873,         "ansible_memory_mb": {             "nocache": {                 "free": 919,                 "used": 77             },             "real": {                 "free": 873,                 "total": 996,                 "used": 123             },             "swap": {                 "cached": 0,                 "free": 15

Using ansible ping module check connectivity between two nodes

Using ansible ping module check connectivity between two nodes Once server and client machine is configured with SSH passwordless authentication and  ansible installed in server, we will verify if ansible can connect from server to client. If you have not configured refer page Login to server node and create a directory to save all the work done in one location Eg:mywork [root@ansible ~]# mkdir mywork [root@ansible ~]# cd mywork/ Create new file called "hosts" under "mywork" and add your client host name in the file as shown below. [root@ansible mywork]# cat hosts [mynodes] node01 Now is the time to check if ansible from server machine able to communicate to client node01 To check this we will use ansible module called ping. Run command as shown below. [root@ansible mywork]# ansible all -i hosts -u root -m ping node01 | SUCCESS => {     "changed": false,     "ping": "pong" }

Setup machines and install Anisble.

Setup machines and install Anisble. Before we begin to install ansible, we will setup server and client machines. I am using Virtualbox to setup two machines. Server Machine Specs: Hostname:ansible.linux.com 2 Network Card: NAT and Internal OS: Centos 6 Client Machine: Hostname: node01.linux.com 1 Network Card: Internal OS: Centos 6 Once machines are configure with OS, we need to setup passwordless ssh connection between server and client. Below are the steps. Step1: First login to server and add host entries with IPaddress in /etc/hosts file. [root@ansible ~]# cat /etc/hosts 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6 11.0.0.62 ansible ansible.linux.com 11.0.0.63 node01 node01.linux.com Same need to be done in client machine Step2: Now from server machine generate ssh private and public key as shown below [root@ansible ~]# ssh-keygen -t rs