Convert your shell commands as Ansible playbook | Ansible playbook to install tomcat server

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello folks welcome back my name is Jared Shanker from Galaxy technologies I am creating ansible video series in this video series we are going to cover multiple concepts I will show you how can you write ansible playbook if you just know shell commands it is quite interesting and for this purpose initially we are going to setup Tomcat server with shell commands once it is working fine then we convert the shell commands as ansible playbook once it is working friend will use ansible variables then we use notify under handlers then we are going to manage different operating systems with the single ansible playbook depends upon the target operating system it has to execute particular tasks after that we are going to convert our ansible playbook as a ansible role which would be quite interesting one these are the things we are going to do in this video series so first let's starts with the setup tomcat server using shell commands if you wish to watch entire series of these videos you can enroll for this course in udemy I have given this link in the description of this video this is my AWS console where I have ansible server on the Tomcat server I have already locked into this system this is Tomcat server which ends with 49 another one is it which ends with 163 it is a ansible server let me show you so it is 49 it is Tomcat server 163 it is ansible server now to install Tomcat server I have procedure first we should install Java once the Java installation is completed we can download Tomcat packages using this URL I have already copied the link over here if you wish you can download it by opening this website and here tar.gz link we should copy right click copy link address this is how we can do anyway same link I have copied over here - be nothing but which target directory we should keep this downloaded packages I want to keep it under slash USR once it is downloaded we need to extract it by using a tear command then start the services these are the steps we should execute to to set up Tomcat server and start the services let's do it by executing commands as it is initially once it is set up then we are going to convert as a and simple playbook and we'll execute as a and we'll playbook let's go on to do this one first we should install Java so this is my Tomcat server let's install Java I think Java is already installed yep it is already installed next to step is download packages onto us our local so let me okay I'm already under us our local no packages are there let me download it all right download is completed now we can see Apache Tomcat packages are there we should extract it I have extracted let's Lestat go inside Apache Tomcat folder under this we have bin directory so under binaries we have ESL script called startup dot Sh currently if I see grip Tomcat Tomcat is not running and let me start the Tomcat services get started now we can see and let's access this from the browser it is on Tomcat server copy the DNS Public DNS and it runs on port number eight zero eight zero that is default value okay so it has been loaded and it is up and running and if you see I have opened port number eight zero eight zero in the security group and spool security group it means it's working fine now we are going to convert to these shell commands as your ansible playbook to do that one let's login to our ansible server PWD now I am under a directory called slash home in a sudden playbooks let's create tomcat setup dot yml okay so amal playbook starts with three minuses followed by description of your PlayBook install Tomcat server then hosts all I want to install on all hosts become true why because this is yeah installation we should have root privileges then tasks this is the actual portion of modifying your shell commands into ansible playbook so the first command is install Java so to install Java we should use a module called yum let's go on such ansible module to install packages okay I will quickly go through with this you can do detailed analysis if you wish so M is a module where you can install packages see here install latest version of Apache yum name state so same thing we can copy yum name Java here not httpd state latest I want to install latest Java this is first to task second a task is download Tomcat server so we are downloading Tomcat server packages to download packages let's search for two download packages you can see ansible module called get URL this is the module we should use to download it's like a double you get command so I'm going to use get URL this is the module under this one we have attribute called URL so we should provide the URL what is the URL we have here so let me copy this URL next disk disk nothing but where do you want to copy these packages /usr local right alright now we have downloaded packages next step is extract these packages all right to do that one let's see what is the module is available extractor tear right because we are downloading tear file you can see an RKO an archive is a command to extract packages and you can see the syntax how you can use so we are going to do this one let's an RKO SRC it is under /usr local on file name is this one right next disk after extracting where do you want to keep I want to keep it under us our local itself another thing which you need to consider while using archive is sorry an archive is whenever you use an archive rrq usually it looks for this file in the local system local system nothing but uh Nancy bill server but this package we are downloading on the target system right for that remote yes sir see so remote source is yes it means go and check in the target server not in the ansible server this parameter should be present in this playbook other ways it looks in the ansible server itself next thing we need to start services and the name is an optional field whether you want to use it or skip it's up to you start Tomcat services so once it is extracted we have you been directly under bin directory startup that seh is there so startup dot H is a cell script let's see what is the module to execute shell script executes shell script so if you see we have your module called shell or even we can use script but it is better to use shell shell module so by using shell or even command module also we can use here I am going to use shell module and the file location is under this location slash bin slash startup dot SH right this is the command we should execute but if you execute this command what will happen whenever you log off from your target system as ans admin this service get stopped I don't want to stop this service that's why I'm using no hope so that even though you log off from the server this service continuously runs in the background right so this is the ansible playbook we have written now we need hosts file VA hosts I will add it as a tomcat server and server name is IP addr is a commander to know about IP address this is the IP address we are adding so cat host host is ready let me test it and Sybil all - M ping - I hosts so try to ping the all the server's which are there in the host systems we have only one server and it can able to successfully communicate with that now let's run ansible playbook before running let me clear the Tomcat installation over here first is let me stop it to stop Tomcat services shut down dot ACH I have stopped it so if I check for services it is not running now go back under remove Apache folder itself I have remote I don't have anything let me clear the screen yeah LS and once we execute playbook once we execute this Tomcat playbook we could able to install Java first but anyway Java is already installed you cannot see any variation then it downloads the Tomcat packages extract it and start the services right so uncie bull playbook - I host Tomcat server dot yml - - check let me check it out whether my syntax is fine or not okay everything is fine this is fine because source doesn't exist that's why it cannot able to extract it let me execute this playbook actually so it's gathering facts anyway and the Java installation it has been skipped because green color means it is already available in the target system so Java is already available it's downloading Tomcat packages right now okay downloaded extractor and started let me see Els and also it has been extracted let's see the previous - e of crib Tomcat all red services also running and if you see refresh this one it should work all right so whatever we have done through the cell script we have done through ansible playbook itself this is how you can convert your shell commands as a and simple playbook now if you see our playbook we have done a lot of hard-coded nothing but if this URL is not available it is going to fail even the location also changes if the URL changes even Java also versions might be changing in these cases we should not use hard-coded value in our ansible playbook for that reason ansible has another concept called variables in next video I will show you how can we replace these values with variables and whenever we want to change some values we no need to modify our ansible playbook at all how can we do we can see that in the next video hope this video helps you to convert your shell commands as a playbook you can try same kind of methodology to convert over shell commands or cell script as a and disable playbook if you wish to watch these kind of videos furthermore please subscribe to our channel and follow us in our Facebook group
Info
Channel: Valaxy Technologies
Views: 43,649
Rating: undefined out of 5
Keywords: aws, devops, valaxy technologies, security, automation, ansible, ansible playbook, shell commands as ansible playbook, Convert your shell commands as Ansible playbook, Ansible playbook to install tomcat server, ansible playbook tutorial, tomcat playbook, tomcat ansible playbook, valaxy devops, ansible devops, ar shankar devops, ansible yum module, ansible get_url module, ansible unarchive module, ansible shell module, how to use module in ansible
Id: tbwAL5aTRPE
Channel Id: undefined
Length: 14min 22sec (862 seconds)
Published: Thu Oct 03 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.