Ansible 101 - Episode 4 - Your first real-world playbook

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Great book. First Ansible book I read and one I still go back to.

πŸ‘οΈŽ︎ 3 πŸ‘€οΈŽ︎ u/theopscorner πŸ“…οΈŽ︎ Apr 15 2020 πŸ—«︎ replies

It's that time of week again! Tomorrow morning (if you're in the US at least), 10 am US Central, 3 pm UTC. Past episodes are here: https://www.jeffgeerling.com/blog/2020/ansible-101-jeff-geerling-youtube-streaming-series

πŸ‘οΈŽ︎ 4 πŸ‘€οΈŽ︎ u/geerlingguy πŸ“…οΈŽ︎ Apr 15 2020 πŸ—«︎ replies
Captions
all right and welcome everybody I have no idea what was going on there my computer did like the funny thing is my old computer which is always dying from these things didn't even it wasn't having any trouble it was just YouTube kept showing me error messages and then it started streaming but nothing actually happened in the real world on the stream so we'll see if this video actually makes it through anywhere after about five minutes of YouTube saying it was streaming I finally see the little placeholder image here so we'll see we'll see if it works or not but I'll talk as if it's working I hope you're having a good week as with every other live stream it would be great to hear in the live chat where you're from if you want to post that there I will take a glance throughout this thing and see what you guys are saying and again if you have any questions if you have any problems or feedback on on the examples or if you see something like on the screen the one of the windows is not lined up well for you to be able to see what's going on please let me know in the comments below here and in the live stream I'm glad it looks like people can see me so it looks like things are working okay I haven't running on my iPad but it looks like it's not showing me what's actually alive okay there we go alright so it is definitely working again this live stream series goes through this book ansible for DevOps and I'm just trying to make sure that my windows are all lined up here ansible for DevOps and we're gonna be taking a look at chapter 4 today in just a couple minutes and doing our first real-world playbook example I am going to switch to screen share here so that you can see the agenda for today first of all I wanted to thank again this month device 42 which is a they make a product that supplements ansible very good very well for for a lot of companies that have lots of IT infrastructure and I wanted to give them a plug I wanted to say that ansible is a great tool for driving IT automation but to make the automation work you need to make sure you have an accurate real-time picture of all your IT infrastructure and that's for device 42 helps device 42 provides comprehensive discovery of your entire IT estate from mainframes to kubernetes and just like ansible it's agentless you can try it for free download a trial at device 42 come and see how it can take your ansible automation to the next level and thanks to them you can get copies of ansible for DevOps and ansible for kubernetes free until the end of April until on lean pub comm so to find those just go to lean pub sir transyl for DevOps you can grab a free copy if you haven't already unfortunately I can't give you free copies of the paper back because there's minimum costs associated with it that I wouldn't be able to do and I recommend getting the lean pub version anyways because I can push updates out to that a lot easier if you get the book for free I will give you free updates forever on lean pub that's how I do things it's kind of like open source book development anyway a couple things I also wanted to go over thank you so much to people who started sponsoring me on github this week so Jerome a CJ Sutton rock out Angela Andrews Pavel Weber or Waiver EE Archibald LV and I guess sake or sake s4 ke you guys have have made this series possible have made it possible for me to be able to buy things like toilet paper and hand sanitizer which are in short short supply these days although we're running along toilet paper and in my region of st. Louis Missouri in the USA it is it's kind of a gamble whether or not you're gonna find toilet paper any given week so I wanted to thank everybody and for some reason github is not letting me check boxes so maybe github having issues this morning - there were a few questions from last week's episode I wanted to cover really quick one thing was somebody commented that my my terminal window is too low in the display and when I would type things down here to be covered by YouTube's play bar so I'm gonna make sure I pull that up this week and again if you have any issues with this live stream please leave a comment leave notes and I'll try to get to those somebody asks what themes and settings am i using in youtube things like highlighting spaces so when I do spaces it shows me how many spaces there are all of my settings are actually stored in my dot files repository so if you search for Girling guy dot files oops dot files it has all of the configuration I use in addition to I have a playbook that I use it's called the Mac dev playbook that manages my Mac I used to have three or four Mac's so I used to run it on all those Mac's but now I just run it on this one and I hope that this one can survive the day you might be able to hear the fan in the background if you turn off the sound a lot but good news on that front and thanks especially to device 42 I think it was fortuitous that they reached out to me and helped sponsor this series because with the funding that I got from that I was able to buy a new laptop this year I wasn't planning on it but this laptop is struggling and last week the battery started to expand in the bottom of the case is now bulging out this is the second time it's happened to this laptop so my advice is don't get a 2016 MacBook Pro even if you get a really good price on it apparently the batteries just have really bad issues anyway so that's where that is somebody also mentioned that in the in the examples of inventory if you've run into hosts keep checking issues you can add this to your multi VARs that was I think from episode one or two you can add strict host keep checking equals no to the ansible ssh common args and that helps prevent the the warnings that pop up sometimes when you run a playbook or run commands and there's host key issues looks like the stream is having a few little issues here and there hopefully it's still going well if you were seeing issues please mention it in the comments it's yeah so good good to see everybody make sure your font is larger in the terminal and sublime yeah i'll actually increase that size a little bit more just because I know some people are watching this on maybe a smaller tablet or device sometimes I forget to do that before the stream starts another thing was somebody mentioned in in in one of the earlier videos that they're they're basic troubleshooting for all all computing but especially Linux or Windows servers is they always ask is it actually plugged in is it turned on is it DNS or is it NTP and that reminded me of the wonderful haiku it's not being us there's no way it's DNS it was DNS I think that that's funny that was from a reddit user SS broski on a sysadmin post it was a year or two ago I don't remember when that was but I was just reminded of that because probably two or three times per month I find some issue that was the DNS wasn't resolving and so something failed it's amazing how much we we rely on that nowadays so thanks for posting those comments please feel free to comment below also if you if you like the series please subscribe to the channel subscribe link is right below me and hit like on the video if the video is helpful to you one last thing before we dive into the example in chapter 4 is I inspired by I think it's Robert I have his link down here Robert de baak who is from the Netherlands which is where my family comes from he created a really nice content repository for all his ansible content so I decided to do that for my content as well because I realized a lot of people don't even realize what kind of stuff I maintain you can see some of it in ansible galaxy or you can browse on github but that's not that helpful so I have a listing here of all of the different ansible content I maintain including operators for kubernetes container images that are built with ansible that are on docker hub and roles and collections all that kind of stuff and I also add a little note about whether or not it's actively being maintained because a lot of people sometimes ask you know the book is actively maintained and my youtube channel is actively maintained but sometimes the project is either older or I don't use it for anything and don't really feel like I can put in the time and effort to make it well-maintained so I wanted to make that more clear by having this listing here and it's funny the Ubuntu 12 contestants 14 images not building fine so I wouldn't recommend using Ubuntu 12 or 14 since they're not supported but if you do need to 12 point oh four is still working somehow so I wanted to mention that and now let's get into the first real-world playbook let me check let's see and someone asked also mark asked is it okay to start with ansible for kubernetes if one is green and interested and Kate s Kate's only yes definitely I write kubernetes for their ansible for kubernetes actually from the perspective of somebody who may have never even used kubernetes before it's it's a book that takes you from like step one all the way to eventually step 100 right now it's like step 25 or step 30 but that's my intention for that book so please again it's free right now so just grab a copy even if you're not going to read it right away because it won't be free after April and a couple more people from the Netherlands hello Croatia it's great to see everybody Norway Poland la la to Kansas City that's an interesting transition see a lot in the reverse there oh and Robertson hi Robert I basically stole your idea for that ansible content site hope you're not too mad about it but I think it would be cool for more people to do that kind of thing to show kind of the open source breadth of stuff that they maintain I know a few people do but it's it's good to see anyway for our first example I'm going to chapter 4 I have one note I grabbed my post-it notes from around the house I have a note to dig out the drain by the back patio there's a drain that's all clogged up and I need to replace it so I guess I'll do that someday probably after this livestream series over but I'm going to go to page 76 and book version 1.2 - I believe this is no 1.2 oh and the the example is the abun - server with solar so I'll get a little bit more into how will how we can use it in real-world implications for it somebody from Nashville Tennessee hello and but one thing that I do a lot of times so somebody might say I need this software running for my server it might be somebody like maybe somebody setting up a marketing website and their marketing website needs a certain feature for a lot of sites that I have built and maintained I I started out doing web development and a lot of the sites were like commerce or lots of data in the site that needed to be accessible and searchable and a lot of people start out using database based search with postgrads or with my sequel and it can work okay but the search is pretty limited you don't have lectures and parsers that are very configurable you don't have search suggestions that work really well and so you start looking at what is a way that I can have have a more robust search solution that something like Google but for my content only and in the old days Google actually made search appliances that had the Google software on it that you could put into your rack and have your search data stored on it and it would have a front-end that looked similar to Google's front-end and it would be really good but they stopped doing that appliance some years ago and they they also had custom site search and things some of those things still work okay but you don't have control over exactly how it integrates you don't have control over the interface as much as you'd want and sometimes it's even harder to set up and maintain and you don't have control over the thing that is doing the search so a lot of people that use Drupal and WordPress and adobe experience manager and Magento and any kind of self hosted system that manages content or commerce products and things like that a lot of these systems integrate with search products search software like Apache Solr and elastic search and some other search engines too but patchy solar was really the first thing that built on top of Apache Lucene for search services and had a pretty good API a lot of it is XML based which is lesson style I guess but more modern versions have made it more accessible and there's libraries for solar integration with every programming language so since that's something that I've had to do a lot I wanted to automate that and a lot of a lot of these tutorials and things you find online have to do with Ubuntu servers so we're gonna use in a bun to server in this case but you can install it in a very similar way on sent to us or on Fedora or Debian or whatever server operating system that you want to use so I created an Amazon ec2 instance in my Amazon account called ansible of unto 1604 test and I added a couple security group rules to it one is to allow me to SSH into the server so I can control it with ansible and another one is to allow me to access the server on port 89-83 because that is going to be Soler's port that it can run on I could configure a different port but that's default and I like using the defaults unless I don't have to or unless I can't so I took the server's public IP address and I put it into an inventory file and that the default the bun to image on Amazon Web Services has a user configured called the bun too so I set ansible user equals a bun too and I put it into this solar group up here and this this again is a basic inventory file that ansible can use to you can tell ansible about your servers using these inventory files and this one is in the ini syntax it's ini style later on we'll get into dynamic inventory and other other inventory styles like Gamal and things like that but for now this is this is how we're telling it so what about the server I'm going to create a playbook and in this case I'm going to create a playbook and a variables file because I have a few variables and I'm gonna set for this solar setup so that I can change versions and upgrade and things like that later on so I'm gonna save touch main gamal one quick note on the playbook name you could call it anything you want often I call the main playbook for a particular server or project main mammal some people call it site llamo sometimes you see playbook Nimal or solar amel it doesn't really matter but it's it's nice to be consist so I always call it made that yellow and I'm also going to create a variables file called VARs Amal and hopefully you can see everything in my terminal and sublime text okay if you can't let me know so in the playbook I'm gonna say hosts solar because that's the group that I created an inventory and I'm going to say become true because when I'm gonna install solar I'm actually going to need to be the root user for most things and I mentioned earlier sometimes you could put become at the Play level and everything that you do is going to use the root user and when you're managing servers you can do anything as the root user so if you're gonna do most things that there's a root user it's okay to do this sometimes you want to do it in the inverse and not be root for everything and only become for tasks that have to become there's there's the whole philosophical debate you could go either way with that in terms of security but we'll leave that for future episodes there's an episode that will talk about security later and then I'm going to add this VARs file under the key VARs files or is that me Amal and this key lets you define one or more variables files that ants will load in before the playbook starts running but before we start installing solar it's good to know how to so I'm gonna search for patchy let's see catchy solar install and we'll see what the official documentation tells us to do there's a lot of other articles for it but look at the reference guide here I know that the current version of Apache Solr is 8 X but the 7 that X for install instructions are pretty much the same so it looks like I need to download a release from here so I'm gonna go there in another window and get there soon it tells me that I need to have the properly sized server in this case I'm on the free tier in Amazon it's not I don't recommend using a slow free tier server for solar the more memory it has the better and the faster disk it has the better because indexing content can be a heavyweight operation unless you have a really small data set so one way that you can do this is just download the the tarball and then expand it and then run it but for production its you'd want to do it a little bit differently you'd want to make sure that it's it's run as a service in system v and all that so there's a section in here prod taking a solar to production there's a section in here that tells you how to do things in production and the download includes an installer that installs a solar service that is running with system v on this server that would allow me to start and stop it and able it at boot and have options that are passed into solar when it starts up for memory and all those kind of things so I'm going to go ahead and do it this way and the first thing that I need to do is download solar so in the VARs I'm gonna I'm gonna set up a couple variables for how to set the solar version and the solar the hash for the Downloads that I can compare the hash when I download the package or download the tarball and make sure that it's the one that I expect so solar 8.5 point O is the latest version I'm going to grab I'm gonna grab a download link from here so this link actually gets me to our mirrors page so on the mirrors page I'm gonna grab a download link it's saying that Berkeley has the best mirror sight for me so I'm going to copy that link and I'm gonna save that for later and I'm going to create a few variables so I'm gonna have I want to download this to a temporary location because I want to expand it and install it somewhere else so I'm gonna say download der for a lot of projects I just have a I'd just download things to temp but you can have have this set up a little differently a solar der this is where I want solar to be installed I want it to be in the opt directory solar solar version that's going to be eight point five point oh and a note on this you can quote this you don't have to quote it either way if it's the only thing that could matter for is if you're trying to compare version strings and things it can be different with you quoted verses don't quote it just something to keep in mind later on in your ansible journey solar checksum would be the SHA what is Chah 512 is what solar stores here if I go over here the sha-512 and that's gonna let me make sure that the when I download this file I'm gonna compare this with what is downloaded to make sure that I'm actually downloading the right file and that's to protect me if if one of these mirrors is compromised and somebody uploads a malicious tarball and it has it doesn't match the checksum then ansible will fail if I if I confirm that the checksum is correct so that's the variables that I'm going to need for this playbook and I have I had the download link which I just deleted there it is I will need that in just a minute when we actually do the downloading with Drupal so for the playbook since this isn't a bun to server anybody on a bun to knows that a lot of times a lot of times you try installing something and then it has an error message because the apt caches are not up-to-date so on every a bun to server ever setup I always add a pre task that is update apt cache if needed and to make this item potent meaning it I can run it once or a million times in a row and it doesn't make a change I can add a cache valid time to this parameter so I'm gonna use the apt module and say update cache equals true and then cache valid time equals 3600 and note again that this is this is one style of writing ansible this is like the shorthand style you can also do this this is the structured style using gamal primitives the only reason I do this sometimes in in demonstrations is just to make sure that you can see everything when I have five or six tests you can see it all in one screen instead of me having to scroll up and down a lot so you might and I usually do this you might want to use this style when you're writing your own automation you know but for now I'm just doing this so don't complain about it too much in the comments actually I don't need another test there and I need to fix this it's update cache that's the first thing it will do also another thing that I typically do if I'm going to install something that configures a service so for example this is going to install a solar service the service might need to be restarted sometimes if I change a configuration value or if later on when I'm building out this playbook I want to be able to restart solar after something happens so I usually add a handler for every service and you add those under the handler section of the playbook and what this allows you to do I'll show you in just a minute first I'm gonna write the handler so name restart solar and service name equals solar state equals restarted and what this allows me to do is if I ever have a task in my tasks section do all right let's see change config command something to change config here I can write notify restart solar and what that does is after this task runs it'll say trigger this handler when the when this play is over and that lets that let's my playbook be able to restart a service without me having to say changes config and if the config is changed then restart the service it's just it saves you a lot of a lot of work because you can notify these handlers from anywhere and there's it's not just for services you can use handlers for a lot of other things too but it's typically something I do I put in a handler for any service that I am installing somebody oh somebody mentioned I don't have the - - - I better add that there we go and I'm gonna grab this URL out of here cuz it's not that's not a valid demo okay so there now it's a pure llamo file because it has starts at the little dashes so the next thing that I'm going to do for the installation is Solar requires Java and it can use Java 11 but we're this particular server is I believe running Ubuntu 1604 and it's hard to get Java 11 on that on that particular OS without doing some some extra hoops and things and adding repositories so the first thing I'm going to do is install Java so I'm going to say name install Java and luckily for me it's it's something that's in the distributions repository so I don't have to do any extra setup here I'm gonna say apt name equals open JDK 8 JDK the state is present so that's going to install Java for me using the apt module and I mentioned this earlier you could use the package module 2 and 4 for tests that you want to make cross-platform which we'll do in later play books you can use package to make it so that it would use apt or DNF or yum or pac-man or whatever the package manager is on your platform however this particular package name wouldn't work correctly on sent to us for example so I'm just going to explicitly explicitly use the apt module to make it clear this is intended for apt based systems Debian and Ubuntu and derivatives the next step is I need to download solar you technically could install solar from the abun two repositories but the abun to 1604 default repositories has a really old version of solar I think it might be like solar 1.4 solar 3 points something it's really old and unsupported so we're gonna make sure that we have I'm gonna make sure that we have solar 8 and that's going to require us to do the installation instructions that are in here taking solar to production so the first thing I'm going to do is download solar download solar and I'm gonna use ansible z' get URL module and get URL has a lot of different options instapoll get URL and again i could be looking this up with a handsome old doc doc get URL that's funny my my brain just puts in a k on there for some reason because i type in docker a lot you can do it this way too but I like the formatting on the the web for it but I will open it here just so you can see what that looks like and you can get get through all the options and things in there but on the web it shows you all the different options that you can pass to it including the check sum which you can use to verify the download files correct and it has a lot of examples here so we're going to use a URL that we got from earlier which is this one that was the mirror that we copied off of answer off of Soler's website and we want to replace the version here with the solar version string that we are the solar version version number that we added in VARs so I'm going to take this variable name and I'm gonna use Jinja to put that in mine right here when I use Jinja in line with any string in the amel technically if it's not at the end or the beginning of the line it would work fine but if I were to do this like that and this whole thing we're Jinja you can see that the syntax highlighting goes a little burrs irk so whenever I use Jinja in a string in any ansible in any Amal I always quote the entire string so I add quotes around the whole thing that could be single or double quotes it doesn't matter now but I always quote when I use Jinja in line and this is the double what is it double handlebars or mustache or whatever is the way to indicate that you're using a variable so I'm going to grab this variable and also use it here because it needs to be there so we're gonna use that as the URL to get ansible is going to get that URL and then I'm going to say the destination will be and I'm gonna use quotes because I'm gonna do another Jinja variable here the destination will be the download Durer which is temps that was defined in VAR c amel right here we're gonna download to their slash solar - solar version dot tgz and the reason i'm specifying the full path to the file including dot tgz and everything here is you can pass a destination for other directory but if you don't pass the full filename that it's going to download the ansible will report a change every time it runs this if that file doesn't already exist so that's one way you can help with item potent when you're downloading files and then I'm going to give a checksum for ansible to check against and that's going to be solar checksum which we defined already over in VAR c amal and this is ansible shorthand for checksums you can put the type of checksum before the actual checksum with a colon separating the two and you can see that in the examples here and it's documented up in here under checksum right here so we have those things and I believe that's it for the downloading I mentioned directory and I mentioned the checksum it's important for security to make sure that you're downloading files that you believe to be legitimate and I'll take a look really quick on some notes here so a wasum asks why why that I do that update apt cache and pretest and not TAS it's more my style of play book that I write so I like to have pre tests as like set up stuff that doesn't really influence like this doesn't matter for solar this is just something that has to happen on all of onto servers and Debian servers so I usually like to throw that into pre tasks and then post has to be clean up stuff that doesn't affect like if it doesn't have to do a solar like if I needed to notify somebody I would do that in a post task or something but you could put this into tasks if you wanted it's it's more a style thing my style is to have pre tests do things that that need to be done before everything else and in the order of this we can get into it more in detail later but basically ansible do pre tasks and then roles which we haven't talked about yet then tasks then post tasks and when it's running through all of the things that it does so there was one good question Oliver Davy says he types docker Composer a lot as a PHP developer I often write composer instead of compose yeah and you're talking about single and double quotes too it's funny in in the amyl it's not there's no real preference it doesn't really matter and llamΓ³ linters won't really complain if you do single or double quotes in some other languages it can actually make a difference so some people prefer double quotes or single quotes for different things because of string interpolation for Jinja and for Gamal it's I haven't seen a performance different difference and I did some testing at one point because I'm like that and I didn't see any significant percentage difference when doing like millions of of instant Asians using the single or double quotes so it's really up to your own style I often use double quotes just because because that's what I do but no linter that I've seen cares either way let's see so I talked about the checksum I'm also I'm also marking up my book here with my notes just to make sure I cover the important things I might even maybe at the end of this series I'll sign the book and give it away or find some way to to do something fun if you have any ideas on what I could do with this book afterwards let me know let's see you'd have to spray it down with some some Lysol or something go to make sure you're not getting corona virus if I have it let's see the next thing that we're gonna do though is we downloaded a tarball and the next thing we're gonna do is use the unarchive module so I'm going to say expand solar and use an archive which is another built-in module and ansible that on archives archives it's pretty self-explanatory and I'm gonna go add a source which is the same as this this is the source of the on archive will be the destination for the download destination will be the download der and then remote source is true and this means that so I'll tell you what that means in just a second it's hard to type and think at the same time and creates I will talk to you about that as well so for on archive by default what it will do is if you give it a source it'll take a file on your local system or on your whatever host is running ansible and it will put it it'll copy it up to the server and then unarchive it on the server if you have a file on the server already that you want to an archive you have to say remote sources true that means that do it all on the remote it's not we're not cop archive up and expanding it all so I'm going to add the creates option here some modules have creates as one of the parameters you can pass straight to it other modules like command and she'll you can actually add creates in part of the command or you can pass it as an argument separately and and I'll show some of those options in the future as well but creates as a way that you can control idempotence because the unarchive module might not know whether or not an archive is expanded because it doesn't know what's inside the archive and it try if it tried to track that it wouldn't do that great you know it would have to store it state somewhere so what we can say is once it's expanded we expect a certain file to exist and if that file exists it doesn't need to try doing this again that's what we're gonna do for creates here is say a download der slash solar - - solar version slash readme dot txt because I know that the readme dot txt file is going to be inside the expanded copy of solar after its Sun archived and how do I know that because I've done this before but otherwise you might do this in a test environment and see or download the the thing manual and see what's inside of it to grab a file that is created another another quick note here is some people who use ansible and are watching this might say why did you use get URL and on archive because on archive can actually do both you can actually unarchive a file directly from a download link so i could put the source as a URL here and the reason i do that is because solar is a little unique again I know this because I know it's not you wouldn't know this until after you tried installing and found issues when you install solar the solar installation script actually looks for the original under the original tar ball when it's doing the installation and if it's not there it will fail so that's why I do this in two separate steps because I need to preserve the tar ball and I need to have the downloaded directory expanded as well but that is something to keep in mind is when you're doing something like this it's often easier just to use on archive and download a URL directly instead of downloading something then expanding it just something to know and the last thing is as mentioned in the solar installation instructions here there is an install solar service script and we want to run that and just for the interest of time I'm not going to go into the script and look at all the options and things I've already found what the options are that I need to install solar correctly on the server but I'm going to add a task to run that script and in this case since it's not like a standard type of installer that the danceable has a module for I'm going to use the command module and then as I mentioned before a lot of times it's easier to use ansible if you can just pass commands and and shell scripts and things into it that you already have or that are documented somewhere and that's one reason I like ansible a lot is because you can kind of have that hybrid where I have some of an Sable's modules but I also can pass in a command which I'm about to do I'm going to say run solar installation script with command and there's a couple good questions I noticed in the chat that I'm gonna get to in just a minute maybe while we're running this playbook downloader slash solar solar version slash bin slash install solar what is it called install solar service SH and you notice that I added a what a close bracket here and this means that this is going to be a folded scaler which means every line from here on down will be put together with one space between them and it's just a way for making commands be a little more legible and readable let me make sure it looks like my head is in the way of this let me make this a little higher there you go now you should be able to see it a little bit better so the command is to run that script and then I'm going to pass it you have to pass it the path - I'm just gonna copy this out pass it the path that the downloaded file which is that tgz that's the same as up here the source and the desktop there so I have to pass it the path to the the tarball and then I say - I opted and that tells it where it's going to install solar which earlier we said we're going to install it into the solar derp I could make this a variable - and there's a lot of things I could make into variables in the script that I made do it if I'm making this script a little bit more robust in the future or doing something like converting it to a role which we'll do later I'm gonna pass it the data directory which is var solar and I'm gonna pass it the user that I want it to create which is solar and the S is solar I don't remember what s is for let's see what that is really quick - yes is that in here it doesn't have a service name so we want the service name to be solar that can be customizable if you want to have maybe multiple versions of solar running at the same time that kind of thing - P is the port that it's going to run 89-83 is the standard instead of fault port so I'll just stick with that and then I'm gonna add creates here and like I mentioned up here it creates as a way to ensure item potency that way it won't run it and rerun this command if it sees that solar is already installed so in an install solar it's going to put it into solar dur /bin slash solar and that won't exist until after the installation is over so that's that's the installation and the installation script for this actually starts the service but I also want to make sure that the service is started and enabled on boot-up so I'm going to add another explicit command here that says I'm sure solar is started and enabled but-- service name is solar state started started if I can spell enabled is yes and again people might be cringing at seeing this this ansible shorthand you can always write it this way too but again I'm doing this for the the purposes of easier easier visibility of the entire script so this is the playbook and you know going over the whole thing beforehand it makes sure the apt cache is updated I add a handler which I'm not using in this particular playbook yet but I probably would use it at some point if I do things like allow you to change configuration like how much memory is available to the JVM or the port that solar is running on then it's going to install Java which is a dependency of solar and then it downloads and expands the solar archive and then runs solar installation script and then it makes sure it's running so I believe that this playbook is all good one thing that you can always do to check if your PlayBook syntax is okay it's a ansible playbook mean that yeah Mel what is it syntax check I often do that in CI and cd4 for a project just to make sure that I'm gonna pass the inventory to just to make sure that the syntax is always correct like if if you add something wrong here like test then I believe that this will fail because that's not valid yeah Mel so it's a quick way to see make sure that your Gamal is at least valid so I'm gonna be able to run this playbook I believe I already accepted the host key for this if not remember earlier in the webcast I mentioned that you can add the ssh options to accept the host key and i'm gonna run this and while it's running out take a look at chat and we'll see what's going on so I'm going to say ansible playbook mein Gamal and let it run and that's the if it can connect to the server someone earlier in chat mentioned why am I not using the vagrant vagrant VM locally for this and I think someone I already answered that person the problem the problem there is my computer was absolutely dying sweet and and that was not even doing too much of downloading and installing stuff so I decided to do these examples for now on AWS VMs on ec2 where I might use something else in the future we'll see just because it was a little easier on my laptop and it would make it not die all the time the good news as I mentioned earlier I'm getting a new laptop so we'll see if that helps me be able to do this stuff without OBS crushing my computer and I wanted to mention some people have asked how I do these live streams and how I have it set up my camera and the lighting and all that kind of stuff I actually have a video earlier on my youtube channel from last week or something like that about how I do live streams so if you're interested in that go take a look let's see there's a couple other questions that were going on here someone said yeah that was the 80s thing you can yeah I mean the the basic principle was with where it's deployed to is you could do it locally in a VM you could even do it in a docker container locally I do some testing that way you can do it in native US you can do it on digital ocean or whatever you just need a server running somewhere basically to do these things someone mentioned pacman reference for the win someone should mention in chat I won't I don't have anything besides respect to give you but what OS this dro is pac-man used for let's see I answered that Thacker composer instead of compose send the book to me I'll take care of it I can't set it yet we're still using it and someone mentioned can you just use on archive I went over that yeah I did it yeah I usually like the multi-line syntax the the more structure DML for these things but like I said it's it's easier for you to see everything that's going on when I when it's a little more compact for these simpler tasks to do why not vs code sublime is lacking I don't know I mean I I'm using a Mac too so some people hold that against me do I need the uninvent line 42 no so if I just did this like I said different modules used current options for it this would not work because the command well first of all creates is not a top-level option and what you can do I forget what it is like args or something like that I forget what the exact syntax is I always have to look it up because I forget but there's an option that you can do that will pass extra arguments to the command module but I I often do it in line like this if I'm just writing a long command anyway either ways but either way is fine but it's probably even better to do it the other way to pass the option in a structured way someone said thanks for the video series you're very welcome Dave I hope it helps are you able to make Auto indentation for work sometimes so that's something I actually haven't set up too well so it sublime it does work because technically if I'm on this line and I want to make a new line this is a new key value pair here but it would be nice to say like if I if I want to go down one space I don't want this extra space in here that's something that you'd have to figure out in your own code editor I've never spent the time to make sublime work exactly how I want but this playbook is done and now to prove the item potent so I'm just gonna run it all again and every task should just report okay okay okay if I did it right over here at least and we'll see if that's the case so so far so good and expand solar is going to be skipped because I use the creates option on it and run solar it's funny it I thought that would report skipped since it sees that Soler's there but it just reports ok I guess that's how command works when it sees the file as already already created so now the cool thing is I can go to the server you might be thinking maybe you could too since it's a public IP but if you try it you'll fail but I'm gonna go to the server 89-83 and I should be able to get solar here and here it is it started three minutes ago and we ran the playbook it's running solar 8.5 you can see how much memory is available to it by default and here's all the options that Solar is using on its boot so this this example is a little bit simple in the real world I would also have a couple tasks to create a solar core and it would do that automatically instead of making going to the admin and do it here and create a folder on the server but but this is now a completely functional solar server that you could start integrating with Drupal or WordPress or experience manager whatever system that you're using that uses Apache Solr and really from here that most of the things that you would do this playbook or maybe make some of these things more parameters in case you're running different servers on different ports that kind of thing and you might also add some more solar configuration like being able to change the port being able to change how much memory that JVM uses by default it's 512 Meg's is the xmx math.max or whatever it is but you could increase that or decrease that as needed but this is this is how I started it's funny I run a service called hosted Apache Solr and in the first couple years I had maybe five or ten clients and I had one server and it was easy to configure everything and I just did it all by hand but it's time went on and I got hundreds of clients on I think I'm up to 80 or 90 servers now it was much harder to manage all of that with shell scripts so that that was the first thing that I started using ansible on and I still use playbooks very similar to this and I have a roll called Guerlain guy that solar that does a lot of the stuff but a little bit more configurable that basically runs this service so this is not far from what is done to actually build production infrastructure and you could you could even use this playbook that's from the book for very simple use cases because you know if you have a site that only has a few hundred or a few thousand pieces of content on it it could all be indexed in under 512 Meg's of RAM but that is the example for today is there anything else that I wanted to talk about let's see hosted Solr and and all that kind of stuff oh I have a quote to live by I forgot to do this for the first couple of chapters but in the book you'll notice at the bottom of certain pages so this is chapter fours quote I always have the cows a little cow icon with a special quote and you know it's ansible for kubernetes I use Star Trek quotes because kubernetes has a heritage of Star Trek lore and folk dumb folklore whatever it is but today's quote is ever if everything is under control you're going too slow and that sometimes is a little too too true other times it feels like things are just going crazy for no reason at all but I hope you like today's episode and again if you did like it whoo I even made for this week I'm starting to figure out how OBS works I made these little social links below me if you like today's episode please go ahead and click the like button below here and subscribe to the channel I have a lot more good content coming future episodes we're going to talk about testing Play Books both simple tests and also with with molecule we're going to go into a little more deep dive of different advanced things that you can do with Play Books we're going to talk about roles and eventually we're going to start talking about some of the other more advanced use cases in the later chapters I probably I'm still trying to figure out and I would love to hear your comments you can leave a comment on here or ping me on Twitter or something I'm not going to do every single example in the book because that might take years for us to do but I would like to pick a couple of the best examples maybe from each chapter and go through them the ones that highlight most of ansible stuff but if you want to mention which things you're most interested and that's really helpful for me I know every single person almost has asked for molecule testing so I'm definitely getting to that very soon don't worry but again if you like this stuff like and subscribe and all that stuff and if you are able to in addition to trying to support your local food pantries and people who are having trouble right now with jobs and things if you like this stuff and you want to see more of it please consider supporting me on github github sponsors which is right here patreon which is right here can't really support me on Twitter but there that is over there I guess but thank you for watching the stream today I hope to see you next week it'll be same time same place 10 a.m. US central or 3 p.m. UTC and hopefully hopefully at some point we can start seeing each other in person again there were a lot of different events this year that I've already missed out on networking opportunities but I feel somewhat connected being able to do these streams so hopefully you get something out of them and I will talk to you next week and we'll see if the stream actually ends on time judging by the way it started it could be 10 or 15 minutes of me standing here staring at the camera
Info
Channel: Jeff Geerling
Views: 30,473
Rating: 4.9827213 out of 5
Keywords: ansible, automation, playbook
Id: SLW4LX7lbvE
Channel Id: undefined
Length: 51min 27sec (3087 seconds)
Published: Wed Apr 15 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.