Skip to content

Latest commit

 

History

History
118 lines (103 loc) · 4.08 KB

File metadata and controls

118 lines (103 loc) · 4.08 KB

Ansible How to install on your VM machine ubuntu

1. update first your apt

sudo apt-get update

2. Ansible use this command for install ( It only needs to be installed on the master-PC )

sudo apt-get install ansible

3. Next need to configure password less SSH: First need to create a SSH key pair on AnsibleMaster

ssh-keygen

this keyfile generate on root folder

cd root/.ssh

rsa_key

(press enter for all options)

4. To copy the public key type command

cat .ssh/id_rsa.pub

rsa_pub

5. and select the key to copy In all the host nodes type command

vim .ssh/authorized_keys

and paste by right clicking From AnsibleServer ssh to all the nodes once then logout: ssh 19X.16X.1.1

* Configuring Host File

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

ip insert

7. Ad-hoc Commands & Modules in Ansible

Example 1: Use the ping module to check if a host can be pinged

ansible ip-192.168.x-x -m ping

ansible_ip

Example 2: Create a new user by using the user module

ansible ip-172-31-12-148 -m user -a "name=demouser state=present"

ansible demo user

8. Ad-hoc Commands & Modules in Ansible (cont)

Check if demouser has been created in host

id demouser

9. Install a package on the host machine using apt module

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"
* Create and Execute a Playbook

11. Change directory to /etc/ansible:

cd /etc/ansible

12. Use vim editor to write a playbook:

vim demoplaybook.yaml

13. Type this command to execute the play:

ansible-playbook demoplaybook.yaml

* if you get any error like this don't panic just follow the instruction-

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?

check the process (package manager for handling software). Use this command:
ps aux | grep -i apt

If you see that apt is being used by a program like apt.systemd.daily update,

Method 1

sudo killall apt apt-get

Method 2

sudo lsof /var/lib/dpkg/lock
sudo lsof /var/lib/apt/lists/lock
sudo lsof /var/cache/apt/archives/lock

You can now safely remove the lock files using the commands below:

sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock

[ ] now install your any packages

* Here a demo install java by playbook -

Java playbook

install process done Install java by playbook_yaml Java install done on host

install tomcat apache