sudo apt-get update
sudo apt-get install ansible
ssh-keygen
cd root/.ssh
(press enter for all options)
cat .ssh/id_rsa.pub
vim .ssh/authorized_keys
and 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/hosts
Now 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 ping
Example 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 demouser
ansible 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/ansible
vim demoplaybook.yaml
ansible-playbook demoplaybook.yaml
E: 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 apt
If you see that apt is being used by a program like
apt.systemd.daily update
,
sudo killall apt apt-get
sudo lsof /var/lib/dpkg/lock
sudo lsof /var/lib/apt/lists/lock
sudo lsof /var/cache/apt/archives/lock
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock