Wednesday, December 2, 2020

Lab1 - Install and configure ansible, and install package on worker node using ansible

 
1. Check if ansible is installed on your system.
# rpm -q ansible
# rpm -qa  grep ansible

2. Check/setup your repo
# yum repolist
# yum install ansible

No match for argument: ansible

3. Install ansible using pip
# python -V
# pip3 install ansible
# ansible -version  # Note the config file location

4. List your ansible hosts
# ansible all --list-hosts

5. Define your inventory of hosts
# vi /root/myhosts
w1 192.168.10.51
w2 192.168.10.51

google for ansible inventory, read through it...

# vi /etc/ansible/ansible.cfg
# add the following contents
[defaults]
inventory = /root/myhosts
wq!

# ansible all --list-hosts
# ansible all -m ping

6. Now, lets go ahead and install one software package on worker node.
- Login to worker node and check if firefox is installed, If yes, remove it.
# rpm -q firefox
# rp remove firefox

7. Google for ansible package module
go to docs.ansible and read through, look at the example.
check state -> present/absent

# ansible all -m package -a "name=firefox state=present"
error: install sshpass program

# rpm -q sshpass
# yum install sshpass
# pip3 install sshpass
still failed to install.

Google for epel release package, download and install
# wget <http://path-to-epel>

# rpm -ivh epel-release-latest-8.noarch.rpm

# yum repolist

# yum install sshpass

# ansible all -m package -a "name=firefox state=present"
[root@master ~]# ansible all -m package -a "name=firefox state=present"

[root@worker1 html]# rpm -q firefox
package firefox is not installed
[root@worker1 html]# rpm -q firefox
firefox-68.7.0-2.el8_1.x86_64

[root@worker2 html]# rpm -q firefox
package firefox is not installed
[root@worker2 html]# rpm -q firefox
firefox-68.7.0-2.el8_1.x86_64



[root@master ~]# ansible --version
ansible 2.9.14
  config file = /etc/ansible/ansible.cfg

[root@master ~]# more /etc/ansible/ansible.cfg
[defaults]
inventory      = /root/myhosts

[root@master ~]# cat myhosts
#[masterserver]
#master ansible_user=sam

#[WebServer]
#worker1
[mylb]
master  ansible_user=root ansible_ssh_pass=changeme ansible_connection=ssh


[myweb]
worker1 ansible_user=root ansible_ssh_pass=changeme ansible_connection=ssh
worker2 ansible_user=root ansible_ssh_pass=changeme ansible_connection=ssh

[root@master ~]# cat /etc/hosts
192.168.56.5    master  master.expanor.local
192.168.56.6    worker1 worker1.expanor.local
192.168.56.7    worker2 worker2.expanor.local


No comments:

Post a Comment

Git branch show detached HEAD

  Git branch show detached HEAD 1. List your branch $ git branch * (HEAD detached at f219e03)   00 2. Run re-set hard $ git reset --hard 3. ...