Professional Documents
Culture Documents
Kubernetes Is An Orchestration Tool But Ansible Is A Configuration Tool
Kubernetes Is An Orchestration Tool But Ansible Is A Configuration Tool
sudo -i
yum update -y
yum install python-pip -y
python –version
In controller run
sudo amazon-linux-extras install ansible2 [to add ansible repository]
yum install ansible
exit
Now go to controller
cd ..
cd /etc/ansible/
ls
sudo vi hosts
[webserver]
<Private_ip-of-webserver>
[database]
<Private_ip-of-database>
ping means you are requesting connection & pong means you got response.
Now we will install git & vsftpd (used for file transfer) in webserver from controller
Now go to webserver & check whether git & vsftpd was installed properly
git version
Now check whether ftp is working properly on webserver or not – go to browser & type
ftp://<public-ip of webserver>
Now install ftp in webserver
Now go to browser & check – you can see ‘test1’ file inside pub.
04october2020
In controller instance
ansible -m yum -a "name=httpd state=present" webserver --become
In controller run
ansible -m service -a "name=httpd state=restarted" webserver --become
(to start httpd service)
mkdir dir1
cd dir1/
vi index.html
<html>
<head>
<title>
A Simple HTML Document
</title>
</head>
<body>
<p>This is a very simple HTML document</p>
<p>It only has two paragraphs</p>
</body>
</html>
In controller
sudo mkdir -m 777 /tmp1
cd /tmp1
vi index1.html
<html>
<head>
<title>
A Simple HTML Document
</title>
</head>
<body>
<p>This is a very simple HTML document</p>
<p>It only has two paragraphs</p>
</body>
</html>
Go to browser & type <public-ip-of-webserver>/index1.html (you can see the html page which you
created)
Topic: Playbook
In controller run
cd /
sudo mkdir -m 777 dir1
cd dir1/
sudo vi file1.yml
---
- name: install vsftpd
hosts: webserver
become: true
become_user: root
tasks:
- name: install package vsftpd
yum: name=vsftpd state=present
- name: write the apache config file
service: name=vsftpd state=restarted
ansible-playbook file1.yml
In webserver run
cd /var/ftp/pub
(If this command gets executed successfully then it’s installed)
Now go to browser & type
ftp:// <public-ip-of-webserver>/pub
https://docs.ansible.com/ansible/latest/user_guide/playbooks_intro.html
10october2020
Q: If you can use shell then what is the need for playbook?
A: We can implement Infrastructure as a Code (IaaC) with the help of script files in playbook.
nohup - means that you don’t have to start the server again & again, even if the server stops then as
soon as the service starts the server will also start automatically
tasks:
- name: install java
yum:
name: java
state: latest
- name: download tomcat
get_url:
url: https://downloads.apache.org/tomcat/tomcat-8/v8.5.58/bin/apache-tomcat-8.5.58.tar.gz
dest: /usr/local
- name: extract tomcat
unarchive:
src: /usr/apache-tomcat-8.5.58.tar.gz
dest: /usr/local
remote_src: yes
ansible-playbook myplaybook1.yml
ansible-playbook myplaybook1.yml --syntax -check
11october2020
Note : if you want to send a file on Jenkins(sender) instance to Controller(receiver) instance, then
the public key of Controller instance should be present in Jenkins instance.
On Jenkins instance
cd /var/lib/Jenkins/workspace/Deploy/target/
ls (you can see addressbook.war)
cd
mkdir copy1
sudo mv /var/lib/Jenkins/workspace/Deploy/target/addressbook.war copy1
cd copy1
ls (you can see addressbook.war)
Now go to Downloads folder in local drive of your PC and open the pem file in Notepad++ and copy
the entire content
On Controller instance
sudo vi myplaybook3.yml
---
- name: install tomcat server
hosts: database
become: true
tasks:
- name: install java
yum:
name: java
state: latest
- name: download tomcat
get_url:
url: https://downloads.apache.org/tomcat/tomcat-8/v8.5.58/bin/apache-tomcat-8.5.58.tar.gz
dest: /usr/local
- name: extract tomcat
unarchive:
src: /usr/local/apache-tomcat-8.5.58.tar.gz
dest: /usr/local
remote_src: yes
- name: copy war file
copy: src=/home/ec2-user/playbook/addressbook.war dest=/usr/local/apache-tomcat-
8.5.58/webapps
cd /usr/local/apache-tomcat-8.5.58/webapps/
ls (you can see addressbook.war)