Getting Started with cloud-init

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello again everyone and welcome back to learnlinux tv in today's video we're going to take a look at cloud init cloud init is awesome and unfortunately in my opinion it doesn't really seem to get the love or attention that it deserves and that's a shame because it's very useful a good use case for cloud in it is when you want to create your very own linux deployment images and there might be a few things that you want to automatically handle every time you deploy a new linux server from that image things like ensuring a default user is created your ssh host keys are regenerated and there's all kinds of things that you can do with cloud init and we're going to take a look at some of those things in this very video now before we get into that i want to take a moment to mention the sponsor for today's video lenode lynode has been doing cloud computing since 2003 which is actually before amazon web services was even a thing on the node's platform you can get your server up and running in minutes and they include all of the popular distributions such as debian fedora ubuntu and get this even arch linux and let's be honest what could be better than a linux focused cloud server provider that allows you to tell all your friends i run arch the note has multiple server plans available to make any app scalable and flexible you can use it to host a blog a vpn server a minecraft server and much more in fact the node is the chosen platform that's used to host the entire web presence of learnlinux tv and lenode offers 24x7 365 support regardless of plan size so you can get live help from a real person when you need it new users can get started right now with 100 in credit towards a new account and i highly recommend you check them out because lenode is awesome thank you so much to lenode for their continued sponsorship of learnlinux tv i really appreciate it now let's go ahead and dive into cloud init on the screen right now i'm connected to my linux server that i'm going to use as the example server for today's video now it really doesn't matter which server platform or provider you are using this will even work on a physical server for example but what i'm going to be doing is using ubuntu as the reference distribution and most of what i'm going to go over should apply to other distributions as well you might have to adjust some commands accordingly to fit other distributions if you're not running ubuntu but if you're running debian that's probably even better because virtually everything should carry over to debian since that's the parent distribution of ubuntu anyway so let's go ahead and dive in now the first thing that you should do is find out whether or not cloud init is already installed on your server some server providers provide cloud init as part of their default image some don't at the end of the day it just depends on where you received your server from could have been a manual installation of ubuntu server maybe you received your instance from a cloud server provider such as lenode or maybe you're running it in virtualbox regardless we can run the following command to see whether or not cloud init is installed on our server so i'm going to run dpkg dash dash git dash selections and i'm going to grep for cloud init and in my case it is already installed you can see it in the first line right there if cloud init is not already installed on your server then you can install it with the following command now normally i would tell you to run sudo before any command that's going to make changes to your server i'm logged in as root i don't actually need sudo for anything if you're logged in as a local user account or a non-root user account then you will need to use sudo i'm going to omit that but what i want to do right now is run apt update that'll help me make sure that my package repository index is fully up to date i'll press enter and there we go next if you don't already have cloud init installed on your server then you can install it with apt install and then cloud hyphen in it just keep in mind like i mentioned if you are not running under root you will need to use sudo that's the last time i'll mention it on my end even though i already have cloud init installed on my server it was already installed in the image provided to me by lenode what i want to do is actually remove it and completely purge it so i can start from scratch so to do that i'm going to run after remove dash dash purge cloud hyphen init and again you should only have to do this if cloud init was already installed on your server that's going to completely wipe it out for me and then next i could run apt install cloud hyphen init and that'll give me a fresh copy of cloud init that should run pretty quickly and that's it so what i'm going to do now is change my directory into the etsy cloud directory and inside there if i list the storage you can see i have some configuration files already there and the file that we want to pay special attention to is the first one here cloud.cfg that's the file that we're going to be working with let's make a backup copy of it just to be safe so i'm just going to make a copy of it and append back to the end of the copied file simple enough next what i'm going to do is open that file in an editor i'll use nano at least for the purposes of this tutorial normally i use vim nano is just easier to explain in a tutorial video so if you want to use a different editor go right ahead and some tutorials will actually start you off with a blank cloud config file and while that's probably okay i don't like to do it that way i like to start with the distribution supplied version of the cloud.cfg file because there might be distribution specific customizations in there that we might want to take advantage of now there's several things that i'm going to do in this file i'm going to make various changes and i'll explain to you exactly what i'm doing now what i recommend is that in a browser and i already have it open that you pull up this page right here i will have this linked in the description down below this is a list of modules for cloud in it and no i'm not creating a video just to basically tell you rtfm but the reason why i'm pointing you to this particular web page is because in the config file that we have in front of us in the terminal there might be a line in there that you're just curious what it does and pretty much everything in that file that's there by default will have a listing here that you could read that'll let you know what that particular module does if nothing else it's good just to bookmark this page in case you might need it later anyway what i'm going to do right now is remove a few sections so basically what i do is i scroll through the list and if anything doesn't apply to me i get rid of it now you want to be careful if you don't really understand what something does then you may as well just leave it alone in my case there are definitely some things here that i know for sure i will never need so what i'm going to do is remove those things for example this line right here bobu that's not an application that i actually use so i'm going to get rid of that line scrolling down we have some more things here i'm not personally using puppet i don't use chef m collective i think is part of puppet either way i don't use it and i don't use salt either so if there's anything here that you know for sure that you're not going to use you can go ahead and remove it now back at the top of the file just going to keep going up here we're going to customize this section right here what this line is instructing cloud init to do is create a default user every distribution is going to have its own default user for example on debian the default user is going to be debian on ubuntu the default user is ubuntu now personally i don't like having a user named ubuntu on my systems so what i like to do is comment this out now what you're supposed to be able to do is rename the default user to whatever you want it to be i've tried it and anytime i do that it completely breaks the install and i can't get in i have no idea why it is what it is so what i do instead is just comment out this line and then if you scroll down there's going to be a section that's dedicated to the creation of the default user it's quite a ways down and it starts right here we have default user and this is where you could change the name of that default user in the case of ubuntu like you see here it's called ubuntu again i've tried changing it it makes everything fail and i don't want to be locked out so what i'm going to do is comment out every single line in this section that's going to make sure that the default user is disabled now we're going to scroll all the way back up here and just remember this user section right here we need to come back to that i'm going to save the file and exit for now but make sure you do not reboot your server though there's actually some additional customizations we need to make to this file but what i need to do right now is create a password hash for my user so i'm going to save the file and exit it's ctrl o and then enter in the case of nano to save the file and then ctrl x to exit out next we're going to need access to the mk pass wd command in my case as you can see here i do have access to that command if you don't at least in the case of ubuntu and debian then you can install the whois package to get access to that command so i just did a search for that package and the last item here who is in green a few lines from the bottom that's the package i was referring to it's already installed so we do have access to it and that's good next what we can do is use the mk pass wd command to create a password hash for the user that we're about to create so we type mk pass wd dash m and then sha hyphen 512 just like that it's going to ask for a password but it's not asking for the user's password or the password of the user that we're logged in as right now what we should type instead is the password that we want the new user to have so i'm going to type that in right now [Music] and as you see here we have a password hash so we're going to copy that and then we're going to return to the file that we were editing so back in the user section you can add a new section for the user that we want to create and i'm going to create that right now so right here i'm going to type hyphen and then name colon and then the name of the user that i want to create on the next line i'm going to line up the cursor underneath the end and then i'm going to type lock underscore pass wd i'm going to set that to false and that means we don't want to lock the password for this particular user and then on the next line we'll type passwd and then colon and then right here we'll paste the password hash that we grabbed from the previous command and there it is and it wrapped a little bit but you get the idea you won't be copying that particular password hash so just use whatever one came up when you ran the mk pass wd command for yourself so the fact that that's wrapped shouldn't really matter and then here we're going to type geckos with a colon and that's where you could type your user's name not the username but the actual name of the user so you could type your first and last name here if you wanted to i just put my first name that's good enough for me now there's some additional lines that i want to create here but i'm just going to paste them in it's probably better than watching me type and make a bunch of typos anyway so i'm going to paste right here the remaining lines for this section for the ssh authorized keys line what we could do right here is add an ssh key if we have one and having an ssh key is highly recommended so if you don't have an ssh key i highly recommend that you create one it's beyond the scope of this video i do have other videos on my channel that will describe the entire process so if you don't have a key and you don't plan on using one you can delete this line as well as the one underneath it now for groups you want to pay special attention to this one because you may not have the same groups on your system as i have on mine if i scroll all the way to the right you'll see that the line wraps a bit we have some remaining groups here so just make sure that each of these groups exist on your system before you add them don't just copy and paste this because i'm not really sure what would happen if you copy and paste groups that you don't actually have on your system just cross reference the groups that you have on your system along with the groups that i have here when it comes to sudo on some distributions that could be called wheel for example so just make sure that and i'll leave it up to you to make sure that you have the proper groups i will have a link in the description below that will point to the wiki article for this video so you could copy and paste all the commands that i'm using here again just make sure that the groups you see on this list actually exist on your end and if it doesn't just don't include it in this list in the config file right here we have a line of config for sudo and that's just going to set the sudo options for the user that we're creating and then finally we're setting the shell for the user in this case slash bin slash bash so now there's a few more lines of configuration that i'm going to walk you through the next thing that we're going to search for is time zone it should already be in the file i think it's a bit down here here it is now what you can do is actually add your time zone right here if you know what it is go ahead and add it i will have a link in the description below that will point to a list of time zones that you can add if you're curious in my case america detroit that's close enough now at the end of the file and i mean the very end of the file we're going to add an entirely new section i'm going to paste it in and here it is the boot command option allows us to run a command at first boot in this case i'm running the date command and i'm sending the output to the birth certificate file in the etsy directory this is a little silly but i find it fun what this means is that if you create an image and you have a config file a cloud init config file with this command in there then the first time you create a new server from that image with this cloud init configuration it's going to basically put its own birth date in this config file so if you're curious when this server came online for the first time you could find the date right here in this file again it's kind of silly but a little fun now perhaps more useful is the fact that we could tell cloud init to make sure that several packages are installed by default so i'm going to paste it in right here and there we go so in my case i'm having it install git tmux and vim and this is a very specific version of them the one that i like to use that has some extended support for scripting languages this isn't required just a fun thing to add here if you have some packages on your end that you want every server to have you may as well add them here now what i'm going to do now is save the file control o and then enter and then control x next what we're going to do is change directory yet again and inside the directory that we're already in is a subdirectory called cloud.cfg.d and inside there we're going to create a special file and this is the name right here 99 hyphen fake underscore cloud.cfg most likely this file will not exist by default so i'm going to paste the contents into this file and then i'll give you a little bit of information as far as what it's doing and here it is so the reason why we're creating this particular config file is because normally cloud init needs a data source and the data source is often a web server that is able to connect to that contains some values that it'll use for its configuration and on some cloud providers such as aws and others there's actually a dedicated url that it can use to connect and retrieve that data now in my case at least when it comes to lenode there's no actual web server that's exposed that provides information to cloud in it now one option is that you can create a web server that will provide that information and that's beyond the scope of this video but with the no cloud option even though this is a cloud provider we're just kind of taking the easy way out and just bypassing that system altogether and that's all this is doing so i'll save it ctrl o and then enter and then ctrl x go back to the other directory now hopefully when i created the cloud.cfg file i didn't have any typos but one command that you might want to run before you run anything else is cloud hyphen init and then clean this is especially useful if cloud init has already run on your server in which case is probably not going to run when you reboot so essentially this resets cloud init and actually there's one more thing that i want to add to the cloud.cfg file and i forgot to mention this earlier so we're going to bring that back up and then we're going to scroll down and we're looking for this line right here preserve hostname and what i'm going to do is paste a few more lines right here so i added these two lines and the first line right here hostname as you might suspect is giving us the option to set the hostname that we want for the server right above it we have preserve hostname false if yours also says false we want to leave that alone if we set that to true it's going to preserve the current hostname not actually use the one that we want to set it to that we're setting here in the line down below and then you can simply change this hostname to whatever you want it to be then the third line here what that's going to do is update the etsy host file to ensure that it also references the correct hostname as well and that's important because we want that to be consistent so i'm going to save the file again ctrl o and then enter and ctrl x to exit out now before we go any further there's a little bit of errata to go through first there's a file in the etsy system d directory that pertains to networking and when that file exists it prevents cloud init from working so we'll need to remove it and it's actually this one right here it's a symbolic link named 99-default.link and i did some googling and from what i understand someone else had some luck getting this to work by just removing that file so let's just get rid of it now just to make sure that everything is clean i want to run cloud hyphen init and then clean one more time and then now we should actually be able to run cloud init if nothing else this will help us test that the config file is correct normally what you would do is shut down the server and take an image of it so that way the next time it comes up it's going to apply all the configurations but before we do that we want to make sure that the cloud.cfg file is correct so let's go ahead and run it we're going to run cloud hyphen init init just like this moment of truth let's see what happens and that's it you can see how quickly that ran and we could see some changes were already made for example the host name is set my hostname was what i put in the configuration file also right here we actually have the hostname represented in the etsy host file as well that's pretty cool and then right here we have the birth certificate file and inside there is the date that this server would have been created if it was actually being created this was just a test so if this was a new server deployment this would actually be the quote unquote birth date of the server but what you're seeing right here is that it's actually working and that's pretty cool so there you go we have successfully set up cloud init and we created a custom config file for it so that way we can create a custom server deployment image that'll automatically set up a few things for us to make our jobs a little bit easier every time we set up a new server so let me know what you think in the comments down below i really appreciate you guys checking this out liking this video and subscribing to the channel and i'll see you again very soon thanks for watching [Music] you
Info
Channel: LearnLinuxTV
Views: 13,454
Rating: undefined out of 5
Keywords: Linux, Tutorial, Howto, Guide, Distribution, Learn Linux, operating system, os, open-source, open source, gnu/linux, LearnLinuxTV, LearnLinux.tv, cloud-init, cloudinit, cloud init, deployment, deploy, distribution, automation, devops, tools, utilities, command line, virtual machine, vm, how to, ubuntu, debian, ssh host keys, ssh, user, bootstrap, automate, linux operating system, linux for beginners 2021, cloud init ubuntu, cloud-init clean, cloud-init tutorial, learnlinuxtv proxmox, cloud init tutorial
Id: exeuvgPxd-E
Channel Id: undefined
Length: 22min 52sec (1372 seconds)
Published: Thu Jul 08 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.