Getting started with Ansible 03 - Setting up the Git Repository

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to video number three in my ansible series now again i know you guys are just itching to get started but there's a bit more that we have to do when it comes to foundational concepts before we can get started and in this video i'm going to give you guys a basic look at version control specifically we're going to create a git repository for our ansible code now you don't actually have to know git or anything about git or even use version control at all in order to use ansible but it is a very good practice to get into because if you use ansible in the real world at a company then you're going to be using version control for your scripts your ansible configuration or whatever you're doing and if you are working at an i.t shop that's not using version control then you really should be using it now i'm not going to give you guys an in-depth look at git because all of the specifics about git that's far beyond the scope of this video but what i am going to show you is the core concepts that are required for the purposes of this series and there's really not that much to learn the very basics of git is extremely easy to learn so let's go ahead and dive in and create a git repository and then i'll show you how to do some basic version control commands as well [Music] so again here i am on my laptop and before we get started we want to make sure that we actually have get installed so we can simply type which and then get and we should get output just like this it should say something like user bin the which command basically allows you to determine where a binary is on the file system so if you have no output at all then you know that git is not installed now to install git you can do sudo apt update to basically make sure that your index is up to date but now that that's up to date we should be able to run sudo apt install get just like that now i'm not going to run it because it's already installed for me but if you don't have it on your end on your workstation then you should go ahead and get that installed and that's only required on the workstation because that's the only machine on which we're going to use git in the first place and that gives you the get command so if you enter it just by itself with no options it just basically gives you a help page right here so let's go ahead and create a repository because if we don't have a repository then git is essentially useless so here on my browser we need to go ahead and create an account so we can go to github.com [Music] and if you don't already have an account we can sign up for one if you do have one you can go ahead and log in now i already have one so i'm going to click sign in but again if you don't have one just fill this out right here and click sign up for github so for me i'm going to go ahead and type in my information to my account here so i'll type in the email address then paste the password because i'm too lazy to type it click sign in and we're here on my github account and what i'm going to do is basically show you how to create a new repository so at this point you should have already created a github account and you should be logged into it so you're probably not going to have all the same things here that i have but what you can do is click the new button right here to create a new repository and i'm going to give mine a name i'm going to call mine ansible tutorial just like that the name is available i don't have any other repository named that so of course it is description is optional and i'm going to make mine public i'm also going to initialize it with a readme file i'm going to go ahead and create repository and here we have the actual git repository that we will use throughout the rest of the series there's nothing here except for this readme.md file this is a markdown file and this wouldn't be here either if i didn't check that box to tell it to create a readme file and i did that basically well so we can have something here but i'll leave that up to you if you want to go ahead and create a readme so what i'll do is increase the font size here so hopefully you guys can see it better so then what i'm going to do is click on this profile icon here and then i'm going to go down to settings and then we have a section ssh and gpg keys right here i'll click on that i have this default test ssh key i'll go ahead and delete that one so now yours should probably look like this unless you've already gone ahead and created an ssh key i'll click new ssh key here and basically we'll need to give it a title so i'm going to call this one j default which is what i named the key that we created before the first one not the ansible one and back up here we have again my tmux session and we need to grab that public key so we're going to cat.ssh basically the first public key that we created the one that does have the passphrase i'll press enter and there we have it in one line so i should be able to highlight the entire thing just like that i'm going to copy that and then i'm going to paste it here and there it is so essentially we are adding our public key to our github account so i'll add it and there it is so now i want to go ahead and get back to the repository so i should be able to do that by just starting to type here ansible tutorial there it is let's go there and we have our repository right here but what we need to do now is download this to our workstation so i'll click this where it says code and it says clone with ssh that's what we want i'll click this copy to clipboard button we'll go back up here to our workstation so now what i'm going to do is type git clone and then i'm going to paste that url that we copied from github which for you should look something like this your username obviously will be different and maybe you gave the ansible repository a different name maybe you just simply called yours ansible for example but i'll press enter here i'll say yes i do want to trust the github server and according to this it looks like it actually did pull it down if you don't have an ssh agent running in the background the chances are it probably asked you for your passphrase but if i list the storage here we have a directory that has the same name as the repository so i'm going to change directory into there and we have that readme file and the readme file is the same as this one right here so if i look at the contents of that it basically has that same little message right here the hash symbol and then the name of the repository now before we can actually work with git we should tell git who we are basically our name and email address and here's how we do that so we're going to type this so get space config dash dash global user dot name and then your name and enter and then the next command is going to be similar so i'm going to take a little bit off the top here and instead of user.name it's going to be user.email and then you type in your email address and you type it in quotes it could be something like j at somewhere.net basically an email address i'll press enter and if you're curious where that is if we do cat and then the home directory dot get config just like that dot get config press enter we have the information here that's basically where it puts that info as soon as we type it in and if we don't do this then git is going to complain if we try to commit changes to the repository without having done that now again we have the readme file right here let's go ahead and edit that so we'll use nano or you can use whatever text editor you want i don't judge but we're going to go ahead and open that in an editor and again we have this little title right here ansible tutorial i'm going to go to the end and just create a few new lines and basically you know it doesn't matter what you put here we're testing how to clone a git repository make changes and push those changes up to the server in this case our server is github so we could do something like this so i just added a dumb little sentence here it doesn't matter again you just want to make some kind of change to the file ctrl o and then enter to save it then ctrl x to exit out so if we take a look at that there it is so we have successfully made a change to a file in the repository that we pulled down but if we refresh this well there's no changes here because we didn't actually push the changes up to the master and we're going to go ahead and do that now so if we run get status it's going to list the changes since the last time you committed code and we can also run git diff against any of the files that come up as changed we only have one so i could just run this and it's going to basically tell you what has changed so essentially it is going to add this line right here so let's go ahead and add that change so we'll do git add readme.md that means that we want to take the changes that are in this file and add them we want to make those changes part of the commit that we're about to do and then if we run git status again we can see that this line here turned green green means go we're going to basically put this file in our commit we're going to send it up to the server but before we do that we have to actually commit it and we can just use the get commit command for that and we could give it a message so dash m so we can say updated readme file initial commit now there are entire articles and how to's written for how to write a proper get commit message and that's beyond the scope of this video we're just going to learn the basics of git enough that we need to know to get through the series so i'm not going to go into too much detail on that i'm not going down that rabbit hole we'll just keep it simple i basically ran the git commit command dash m for message and then in double quotes i just wrote a quick sentence about what is inside this commit what did i change and then i'll press enter here and it says well it's been updated great so if we go down here to our site here to github it's not there yet because there's one more step that we need to run to send the changes up to the server and for that we're going to run git push origin and then master we want to push that to the master branch on the origin i'll press enter well it looks like it worked so i go back here to the repository it went ahead and added this line so essentially what we're going to do is we're going to add ansible code and scripts and things and then we're going to push the changes up to github or whatever your git server happens to be because in the real world you might have more than one administrator that wants to pull those changes down and run your scripts and you especially don't want to have all of your scripts on one computer then your hard drive could die or something like that so even if you are only one administrator if you have everything pushed into a remote repository then you have a little insurance there if something goes wrong now you could ask the question for example what about code that i don't want the world to know about i'm not going to get into creating private repositories in this series but that is something that you can do if you want to you can create a private repository to hide that kind of thing and that's basically again beyond the scope of the video but i just want you to know that it is possible to do that so let's go ahead and just take a quick look at the history if i type history we can see all the commands that we have ran and here at the bottom you can see that we basically opened the readme file in nano so we edited the file and then i use the cat command basically to show you that the readme file now contains changes and then we ran git status which is basically going to show us our uncommitted changed files and it'll show in red any file that has been changed we can use the get diff command against a file to see what in particular has changed when we're satisfied with the changes we can run git add and then the file name to basically say i want to add this file into the next commit a commit is basically like gathering and bundling all the changes together and then sending them all up all at once now you could basically commit all of your changes one by one file by file and some people do that some people are more of a fan of just committing everything all at once it's up to you again get goes beyond the scope of this series because it does get kind of complicated but for now all we need to know is that we're adding the file git add that adds it to the commit then we run git status to basically get a summary of the changes that we have accepted then git commit with the dash m option and then in quotes we basically summarize the changes in this commit and again at this point it's all local to the laptop nothing has went up to github yet but we finalize it by running git push origin master which is going to take this commit it's going to send it up to github or wherever your origin happens to be and this is basically the workflow we will be using for the rest of the series we'll be adding files changing files and then sending those changes up to github so that we have basically insurance like i mentioned before or if you have more than one administrator then other administrators can pull down this repository and run your code so there you go that was a quick run-through of git in this video we created a github repository we were able to pull that repository down make changes and push those changes up to github and that's basically the workflow we'll be using the rest of the series from here on out in the next video we're going to go ahead and install ansible and run some commands which is going to be awesome and that video should be already uploaded on my channel so go ahead and check it out i will see you there you
Info
Channel: LearnLinuxTV
Views: 29,863
Rating: undefined out of 5
Keywords: Tutorial, Learn Linux, ansible, ansible tutorial, templates, ansible templates, devops, ansible tutorial for beginners, infrastructure as code, devops tools, ansible playbook, devops tutorial, getting started with ansible, ansible automation, ansible for beginners, ansible playbook tutorial, ansible 101, ansible training, learn ansible, ansible training for beginners, ansible training videos, redhat, linux, linux tutorial, ansible roles, ansible overview, devops training
Id: FFaMqxpphjo
Channel Id: undefined
Length: 15min 53sec (953 seconds)
Published: Fri Jul 31 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.