Check out a free preview of the full Developer Productivity, v2 course
The "The Environment: Setup Ansible" Lesson is part of the full, Developer Productivity, v2 course featured in this preview video. Here's what you'd learn in this lesson:
ThePrimeagen discusses the challenges of setting up and maintaining a productive environment. He also mentions Ansible as a tool for managing dotfiles and demonstrates how to create a basic Ansible playbook to install NeoVim.
Transcript from the "The Environment: Setup Ansible" Lesson
[00:00:00]
>> Speaker 1: We're gonna get started with, first, the environment. I think the environment is everything that surrounds the development process. It's not the actual dev process that we do day to day, it's everything around that. It's how you install your favorite libraries, how you interact with your operating system, get it the way you want it to be, how you arrange windows, how you arrange screens, or desktops, or whatever you wanna call these things.
[00:00:19]
I'm not really sure what people call them. I hear them called desktops. I think that's probably good enough for me, even though I don't technically have a desktop. So I think that that works for the most part. All right, I think this is the most important kind of starting place, which is a question you have to ask yourself, if I were to give you a brand new computer today, how long does it take for you to get up and running to be productive and then furthermore, how many more days is spent trying to realize that you have certain things on one computer and now you have to reconcile that entire thing.
[00:00:51]
And then over the course of the next three days, you install a whole list of just like small little libraries that are really useful or, I forgot to update my bash, scripts to do this, or my zish, whatever, my zish profile has this extra one little remap in it that I forgot to bring over.
[00:01:06]
And I really like it. And so all those things, they just kinda add up. And I don't ever want to have to think about that. I don't wanna have to think about it ever. And I want something that's super simple that I can understand. I like that experience.
[00:01:19]
The first thing I used to use, this is kind of like I used to use. I showed again, just as where I used to be, cuz in the previous course on this, this is what I used, which was Ansible. For a long time, I used Ansible to manage my dotfiles, to bring everything down.
[00:01:34]
I think it's actually pretty good. There's a lot of great things about Ansible, and there's also things that aren't as great about Ansible. And so, here's some pros and cons that I kind of threw up here. If you've ever used Ansible, there's a lot of documentation. It's can be used more than just for managing dot files.
[00:01:52]
Ansible vault actually is really cool. Ansible vault, if you don't know what it is, it allows you to effectively, it's a two way encryption, so you can encrypt and decrypt your files. So that way, if you have, say, a bunch of codes you want on for like your discord recovery accounts, or all your recovery codes, you could just put on a file, encode it, and then push, put it on GitHub, no one can decode it, unless, if they have your super cool passwords, it'll make a dumb password.
[00:02:17]
I know dolphins are awesome, but dolphins is not a great password. There's a bunch of other cool stuff you can do. It's also just terribly slow. It just, because everything is assuming this kind of remote relationship. It's designed to work with servers and, if you really think about it, your computer might be a server.
[00:02:37]
So it can be just terribly slow and it can also be just really hard for certain tasks, I found that just installing plugins for neovim. It just took quite a few tries to get the thing right, and I just got tired of trying to do that. And caching was kind of annoying.
[00:02:51]
Tags for being able to run certain tasks, though a really great idea. Once you have 100 tasks, it's a pain in the ass, because then you don't have like that all task because. Becomes really difficult and then you just, you find yourself copying and pasting and trying to figure out why some things aren't running or you just never even realize they don't run and then you're very upset with yourself.
[00:03:09]
Also, YAML sucks. I believe I can wholeheartedly say this, me and all Norwegians agree that YAML sucks. And so if you don't know the joke, no is also false in YAML. And so Norway is often abbreviated XENO and then it gets, turns into false. Alright, basic Ansible. So we're gonna create a basic script so I can show you what it's about.
[00:03:30]
So that way you can at least try it out, see how it feels. And if you do like it and you want to use this, then you can at least use this for yourself. We're gonna just simply bring down Neo Vim and we are gonna Build it, and we're going to put it in our path.
[00:03:43]
So if you're on Windows this part might be a lot more difficult, and so perhaps you can just as, just like a watching experience. You can just watch this. But if you're on Mac or some sort of Linux flavor, this should just work out. Obviously there'll be some differences with Mac, and because I'm on Linux, there's gonna be some differences I'm gonna use sudo apt install, you may have to use brew install, or whatever Mac uses, Mac ports.
[00:04:08]
So what is Ansible? From there GitHub, it says Ansible is a radically simple IT automation system. It handles configuration management, application deployment, cloud provisioning, ad hoc task execution, Network Automation. And multi-node orchestration. Ansible makes complex changes like zero downtime rolling updates with load balancers easy. More information on the Ansible website.
[00:04:30]
So you're probably thinking, aren't we talking about dot files? And yes, we are. As I said earlier, if you really squint your eyes, really look at your computer as squint as possible, it's actually a server. That's all it is. It's a server too and things work out that way.
[00:04:43]
All right, so by the way, I know I put this in here last night, so I already said this, but do feel free just to watch this section. It's just more of a learning experience to see something else. This is not my personal recommended way, though I do think it's very interesting, and it could be really useful if you have to set up many computers.
[00:05:02]
If you are someone like I know there's entire places, if you have a company in which you want everyone to have very similar experiences on multiple different type of operating systems, this could be very interesting to be able to be like, hey, when you get here, just do ansible-pull.
[00:05:16]
It's gonna set up everything. Maybe it's a bit better than just a A bunch of bash scripts. Because I can bash scripts can be kind of unwieldy. Given the right circumstances, people tend to hate them. So if you wanna follow along, do a little pip install Ansible. Pip three, preferably if you're still living that python two, seven dream life, I would say you need to wake up to the future.
[00:05:37]
Now, old man, it's everything's great, now, python three is fantastic. All right, so at the heart of Ansible, you're usually working with something called an inventory, and inventory is usually like a list of nodes. We're not gonna be working with that. We are gonna be doing a local host, and that's gonna be good enough.
[00:05:53]
And so we're only gonna be concerned more about playbooks in which, even in this we're not even gonna be doing a lot with playbooks. Question.
>> Speaker 2: Why not? Apt instead of PIP-3.
>> Speaker 1: All right, I mean, at this is kinda like some people prefer their cucumbers pickled, right?
[00:06:12]
You can choose how you want to install it. There's no prescribed way. Anytime I can use that phrase, it just makes me really happy. And this is one of those times. All right, a friend once said, this, I don't actually know what this means, but it seems really funny.
[00:06:27]
Ansible is the helicopter that drops Godzilla. Godzilla being Kubernetes. So since, I just think it's funny to say, I don't really know. I don't actually even understand this. It's just fantastic. All right, so let's just jump right in and start doing this. So this would be your first playbook.
[00:06:40]
It's very simple. So what we're gonna do is we are gonna create a directory called MF Ansible or whatever you wanna call it. That stands for my first answerable, not mother friendship Ansible. It's a little bit different there. So I'm gonna jump over here. I'm gonna do a little maktor.
[00:06:56]
Let's actually, I probably I might have. Yeah, I already have that. Let's There we go. Good, all right, now, hey, fresh system. I've never done this before. Let's just try it together. This would be really fun. So I'm gonna create a new directory called MF Ansible, and in here I'm gonna create a single file called the neovim.yml.
[00:07:21]
All right, fantastic. And with that, I'm just gonna copy over this. This is kind of like the heading to a playbook. It says, hey, here's the name of the task. This is where we're gonna be executing it on, obviously, local host. And here's the list of tasks. For those that can't really read YAML.
[00:07:36]
You don't have a lot of YAML experience, I don't blame you. It kind of looks funny to me too. It's hard to remember when to use dashes and where to use dashes and all that fun stuff, but here we go. We have something we can run now. So with this put in into a YAML file, we should be able to jump back here and we can execute Ansible Playbook NeoVim.
[00:07:55]
And so you should probably see the following output. I'll just do this right here. Here, there's a bunch of warnings about me needing to update some stuff. We're gonna ignore that, because that's just who we are. And there we go. We just ran our first Ansible task. Doesn't it feel good?
[00:08:09]
We did it. We officially did nothing, successfully, and it took a little bit, but we did it. You'll may notice that how I said, Ansible is a bit slow. That's a lot of time spent doing nothing. Can we agree to that? If I put a little time in front of there, we'll see how long it actually takes.
[00:08:28]
If you can see, it took 2.24 seconds user. That's a lot of CPU. We also use a lot of CPU to not do a lot. So a total of 3.813, like... Combined second. So anyways, there you go.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops