sudo apt-get updatesudo apt-get install ansible
ssh-keygencd root/.ssh(press enter for all options)
cat .ssh/id_rsa.pubvim .ssh/authorized_keysand paste by right clicking From AnsibleServer ssh to all the nodes once then logout: ssh 19X.16X.1.1
As root user the host file is under
/etc/ansible/hostsNow you can edit and save the file using vim or nano ( text editor)vim /etc/ansible/hosts
6. Write here your IP addresses of the hosts at the bottom of the file in this format and save and exit vim
Example 1: Use the ping module to check if a host can be pinged
ansible ip-192.168.x-x -m pingExample 2: Create a new user by using the user module
ansible ip-172-31-12-148 -m user -a "name=demouser state=present"Check if demouser has been created in host
id demouseransible ip-172-31-12-148 -m apt -a "name=finger state=present update_cache=true"10. Check on the host machine if finger was installed by typing finger To run a module on all the hosts use “all” instead of IP address
ansible all -m apt -a "name=finger state=present update_cache=true"cd /etc/ansiblevim demoplaybook.yamlansible-playbook demoplaybook.yamlE: Could not get lock /var/lib/dpkg/lock – open (11: Resource temporarily unavailable) E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
ps aux | grep -i aptIf you see that apt is being used by a program like
apt.systemd.daily update,
sudo killall apt apt-getsudo lsof /var/lib/dpkg/lock
sudo lsof /var/lib/apt/lists/lock
sudo lsof /var/cache/apt/archives/locksudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock






