Ansible on CentOS 7
Video url: https://www.youtube.com/watch?v=CvnfzTnpASo
Video Title: How to install on centOs7.
Youtube uoload url: https://www.youtube.com/watch?v=n46ECEBdmJQ&list=PLEiDY15kH-ifcOuZwk4z8gqB1JitGgcne&t=0s&index=19
Youtube upload title: Ansible playbook-How to install on centOs7-by-NCD0318H020
Tasks and solutions:
Task 1 : How to Install and Configure Ansible for IT Management in CentOS 7
Step1:
# Your VM is up-to-date and update epel
1
|
sudo yum update -y
|
Step2:
# Note : Make sure you are doing all operations under root only.
1
|
sudo rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
|
Step3:
# Installing Ansible on your VM
1
|
sudo yum install ansible
|
# View ansible version
1
|
ansible --version
|
Step4:
# Adding the node, setting up key and adding permanent key
1
|
ssh-keygen
|
1
|
ssh-copy-id -i host ip addr
|
Step5:
# Adding host to ansible and creating playbook
1
|
sudo /etc/ansible
|
# In that goto hosts edit the file.
1
|
sudo vi hosts
|
[remote-server] ip-address of the host
# this will let you check whether the IP given is correct or not
1
|
ansible -m ping 'remote-server'
|
# create a playbook with .yml format and add below command into it.
1
|
sudo vi name.yml
|
#in that
—
– hosts: remote-server
tasks:
– name: Install EPEL release for nginx
yum: name=epel-release state=present
– hosts: remote-server
tasks:
– name: Install EPEL release for nginx
yum: name=epel-release state=present
– name: Install nginx web server
yum: name=nginx state=installed update_cache=true
notify:
– start nginx
yum: name=nginx state=installed update_cache=true
notify:
– start nginx
– name: Upload the default index.html file
copy: src=html_files/index.html dest=/usr/share/nginx/www/ mode=0644
copy: src=html_files/index.html dest=/usr/share/nginx/www/ mode=0644
handlers:
– name: start nginx
service: name=nginx enabled=yes state=started
– name: start nginx
service: name=nginx enabled=yes state=started
Step6:
#Creating a pre-requisite directory& file and running playbook for node.
# this file is to be created if ansible cannot create it while running a playbook.
1
|
sudo mkdir html_files
|
# because we are working on ngnix here so we create this file
1
|
sudo vi index.html
|
#running your playbook
1
|
ansible-playbook name.yml
|
# make sure the firewall is disabled on the host
1
|
systemctl disable firewalld
|
# Goto browser
#accessing the nginx host.
1
|
http://hostIp:port
|
#Nginx default port is 80.
No comments:
Post a Comment