Check out a free preview of the full Developer Productivity, v2 course
The "Setup & Build Neovim with 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 demonstrates cloning the NeoVim repository, installing the necessary dependencies, and building NeoVim from source using the "make" command. ThePrimeagen also highlights the pros and cons of using Ansible for this process and compares it to using shell scripts or other methods.
Transcript from the "Setup & Build Neovim with Ansible" Lesson
[00:00:00]
>> ThePrimeagen: So now we need to actually do the entire process of installing Neovim via Ansible. Right, so the first thing we want to do is we wanna clone down Neovim. When it comes to using Ansible, one of my favorite features about Ansible is that the docs are just really easy.
[00:00:16]
Everything is hyper-discoverable, which is good. And ChatGPT can be nice for those that like to indulge in our AI friends. The AIs get 95% of the things correct, but often I find that it just loves to use shell scripts, cuz shell scripts are the ultimate hammer and they work everywhere.
[00:00:35]
And it has a bunch of data about how to write bash. And so when it sees that, that it can just write bash, it just writes bash. And so you'll say, how do you do this? And it'll just be like, bash. And then you realize you have the world's most complicated bash set up when you could've just written bash to begin with instead of having series of gambles that produce bash.
[00:00:53]
It's just not the way I'd personally like to live my life, it's kinda gross. So generally speaking, I try not to use the old AIs when it comes to this just cuz of the outdated or oddly used way it does things. So let's go in here and let's just simply look up Ansible, get clone, right?
[00:01:11]
Right here, it'll probably be, wow, look at that, it's one of my first results, I can't believe it, it's like I've been here before. I'm gonna jump in here, go here, and as you can see, it gives you a bunch of options, what everything means, everything's fantastic. And then below, they do the greatest thing ever, which is just give you examples.
[00:01:25]
This is what I wanna see, this is what you wanna see, this is what we all wanna see, and now we're really happy about it. So what I'm gonna do is I'm gonna go all the way down here, and this one right here, example of cloning of a single branch.
[00:01:36]
So I'm just gonna copy that guy, come over here and jump into my old editor. All right, so I'm gonna go up here, and let's edit this thing and call this one, I'm just gonna give it actually a better name, Install Neovim. It's gonna run on localhost, and I'm gonna go clone Neovim.
[00:01:50]
Now this is kind of an interesting thing to do because if you're setting up your computer to run for the first time, you may or may not have your SSH keys on your computer. Maybe you like to generate them every time you get a new computer. There's a lot of different ways to go about this.
[00:02:03]
If you're using Ansible vault, you can actually take one SSH key and you can vault it up and then put it up on GitHub. And then when you want, you can bring it back down and un-vault it, and boom, you have the same SSH key everywhere. I'm not sure if that's actually a security concern or not, feels like it should be.
[00:02:17]
But at the same time, it's like a really complicated encryption, maybe quantum computers. Quantum computers, they're right around the corner, they're just this close. They're coming for all of your RSAs. All right, so what I'm gonna do here is I'm just gonna get the HTTPS version of that.
[00:02:32]
So I'm gonna go to, what is it? It's Neovim, look that up, I bet you, I even have it completed, yeah, github.com, neovim/neovim. And once this thing loads,
>> ThePrimeagen: All right, I'm gonna go to code, and I'll get the HTTPS. I'm on the Firefox, so I'm not signed in, so it doesn't think I have any sort of, what's it called, SSH keys, there we go.
[00:03:00]
And you can even set destination where you want to check this out. So this is another kind of weird part about Ansible. How do I say home, right? It's not gonna accept something that looks like this, that's just not gonna work out. Well, the nice part about Ansible, again, is that it's really look upable, as I said earlier.
[00:03:17]
So let's jump back here and go Ansible environment variables. Jump in here and look at that, built-in environment lookup, right away. Examples, first one is, in fact, a home lookup, fantastic, copy and paste. And so we're gonna do that right now, I mean, this is senior-level engineering going on here, so there we go.
[00:03:39]
So I'm gonna look up ansible.built-in.environment, home, and then I'm just gonna go/personal/neovim. Awesome, single_branch, yes, version, let's go with 0.10.1. Cuz if I'm not mistaken, if I go nvim --version, I should be on 10.2. I'm on 10.1, I still have the other one in there. Let's go, neovim, for a quick second.
[00:04:01]
Sudo make install, hold on.
>> ThePrimeagen: Yeah, I accidentally, well not accidentally, I was preparing for this. Type it in the password wrong, there's a lot stuff going on here. There we go, fantastic, got this. So now when I go back here, I should be able to go neovim version 10.2.
[00:04:23]
Okay, good, so that way we can prove that as I install these things, I'm actually installing the right thing. And show that this entire process actually works and I'm not just making it up, okay? And yes, I do have a habit of writing before I do anything. I say I'm a chronic saver, okay?
[00:04:38]
If I stop saving so much, the world might actually have a surplus of energy. All right, so let's see, what do we have here? We're gonna clone down Neovim, and we're gonna put it in personal/neovim. So let's just do that right now. I'm gonna go in here and go ansible-playbook neovim.
[00:04:53]
So now this time we have installed Neovim, we're gathering the facts, now we're actually cloning Neovim, it's happening right now. All right, there we go, boom, I've cloned down Neovim. If I go ls ../neovim, you can see right there, we have officially cloned Neovim down, okay, so look at that.
[00:05:09]
So now I have this cool playbook that anytime I run it, clones down Neovim, has all that stuff set up, but we still got more things left to do, right? We actually have to do the installation part and all that. All right, so here you go, this is the expected output, I think.
[00:05:24]
It's close, I did 10.2, you can do 10.1, you can do 9.4 if you really want to. All right, so next, building Neovim does require a few libraries, for those that don't know. These are the libraries that I remember that it requires. It may require more, but I'm pretty sure this is all that it requires.
[00:05:38]
So if we were to be using bash, I would just do a little sudo apt install cmake gettext lua5.1 liblua5.1 dev, and that's that. But since we are not using bash, we are now going to be building it via Ansible. So what I'm gonna do, let's see, yeah, I wanna go ahead there.
[00:05:56]
We're gonna go and we're gonna look up on how to actually use sudo apt. So I'll just do the exact same thing that I've been doing, Ansible, I misspelled that, you can't see my text. Don't worry about it, ansible apt install. Again, it's already built-in module, we'll just do a little copy, a little paste, and baba bee, bada boom.
[00:06:15]
You can actually do little operating switch, kind of like operating system switches here. So that way you could have Brew installer ports install for Mac, and you have Ansible for Ubuntu. So it does make things a little bit nicer when it comes to multi-operating system operations. So if we look through here, we'll notice right away, we have this nice little ansible install right here install a list of packages.
[00:06:35]
That's pretty much exactly what I want. So I'm gonna go in here and I'm gonna do that. And then I'll go Neovim Deps, fantastic. It's really just this simple, this is working with Ansible. A lot of Ansible is just grabbing this, you can get into the complicated side of things, like I said.
[00:06:54]
Getting some of that Neovim stuff is just really annoying at some point. And so now let's just go in here and just get all this stuff done.
>> ThePrimeagen: I don't know why it did that, that seems weird, there we go, fantastic. All right, so we have our Neovim Deps, we can install it.
[00:07:18]
Now with Ansible, you also have this thing called become, which effectively you become the user that you run. So now I actually have the elevated permissions instead of just the Ansible permission. So now can actually do, say, a pseudo app install, as opposed to just an apt install.
[00:07:32]
And so now if I were to rerun this, you would notice right away that after it goes here, it's gonna attempt to clone Neovim. Neovim already is in a good state. So this thing should hopefully run fairly quick. Usually it cashes out pretty quickly, there you go. Can't do that, needs a pseudo password, so we should probably provide a password.
[00:07:53]
If you throw in a little -k, -k, ask for a nice password, throw it in there. And if I typed it in correctly, this thing should just run. And then it'll ensure that I also have all the dependencies installed, so there we go. So now we've ran, now we have all the dependencies installed.
[00:08:08]
And as you can see, we're kind of developing this single script to be able to install everything. I mean, I don't necessarily find this to be a bad experience. I did this for my entire system over the last few years, and it's really nice. Really, what it all came down to wasn't the Ansible part for getting my system up and running.
[00:08:26]
Is for any time I made a change to my development environment and I wanted to update the source of truth into my system, it took 30 seconds. And that was enough for me to say, that's it, I'm rewriting everything. I know, I have my weird hills I die on, and that's the one I die on.
[00:08:42]
All right, so we can keep on going. We pretty much have the exact same code right here. And so, yep, there's a crash, we already went through this. Okay, so now we just have to build, that means we just need to Google how to do the make stuff, copy the relevant instructions, implement a new task, and eventually have some Neovim profit.
[00:08:57]
And so here's how you build Neovim straight from their build MD, which is, you just go into the directory and you do a make with this little RelWithDebInfo, and then a sudo make install. We can do this, what do we call? I'm gonna cheat here for a second, I'm gonna just jump down here.
[00:09:13]
Neovim, it's just make, okay, that's pretty nice, anyways, that's nice. Normally, I wonder why I couldn't find it there. Usually it shows up as the first one. That's actually one of the things that I really like about Ansible, is everything you have a question on tends to be the first thing that just shows up.
[00:09:26]
And so right here, it's Neovim with make. You can say, hey, here's the directory I want to go into, and here's the params that I'm gonna have with make. Okay, fantastic, then I can copy that. So that would be the build, and then this one can be changed into the directory.
[00:09:41]
And target equals install, and then we can have become: true. So now this will do the pseudo make install. And if we have done everything correctly, we should be able to rerun this thing with the super sweet password. My goodness, I think I'm mistyping this. No, I'm not much of a stand and typer kinda guy, I definitely mistyped, ain't no way that's correct.
[00:10:06]
Absolutely correct, I knew I had that first try, just unstoppable. So here's another thing that I never really liked about Ansible. So unless if you're executing it with four, I think it's -V, V, V, V, four Vs for super ultra, very, very, very verbose mode. You don't get to see a lot of what's happening.
[00:10:24]
And so unless if you remember to do that, you're just gonna sit here and you're gonna go, I wonder where it's at. I don't think we're stuck, I just somehow doubt that we're stuck. Let's just jump in here and go like this, hit a top. Is anything running?
[00:10:36]
I mean, it looks like something's running. Ooh, maybe we are stuck, or maybe we just got done finishing. Chrome's taking a lot of time. See, that's one of the bad parts about this whole process is, I don't know what's happening. What's the downside here? And so this is one thing I don't like.
[00:10:55]
My guess is that it might be downloading, okay, here, we're just gonna kill it. We'll throw in a bunch of Vs, okay? Do you see how many Vs I just threw in there? That was a lot of Vs. So now you get a bunch of this stuff. So you get all the tasks that are actually being executed.
[00:11:13]
Now if I remember correctly, I'm not sure if you actually get the output right away. And so this was one of the things that I grew frustrated about with Ansible is just having. I like that kind of tactile feedback of just having it right there. Because I'm not using this to hydrate some other computer somewhere else in which I can monitor a touch easier.
[00:11:37]
Instead, I am just doing it right here for me, right? This is for me, I will like the for me kind of output. And so this might take five minutes to build, so just to avoid this whole thing, I'm just gonna kill it, you get the idea. This looks pretty good, right?
[00:11:50]
All right, fantastic. I'm just gonna kill that, and we're just gonna move on. So there we go, everything looks pretty good. This is all the same, you'll notice that this is the same too, we do the exact same thing. We're just to change into the directory, do a little target install, bada bing bada boom.
[00:12:04]
And that is Ansible. That's what it takes to create something that would give you your own freshly built version of Ansible. You can change that little version number, and it'll check out a new one, then it will do a new build. And we can kinda move on from there.
[00:12:19]
It's pretty easy to control, I don't really feel like it's hard to understand. I think some people prefer to avoid bash, because there's the 400 rules of bash. And once you memorize the 400 rules, bash is really great, but until you do, bash is really, really horrible. And I don't really blame you on that one, I have just a few of the rules memorized, so I'm pretty good at it.
[00:12:40]
So it feels really easy to attempt to avoid that entire side of things and use something that's a bit more on the rails like this. This is very clear, I mean, in the end, even though it's verbose, it's extremely easy to tell exactly what each step is doing.
[00:12:55]
And so it feels really, really nice. But I don't want to use that anymore, I've decided that I don't like it anymore. And so for me, I'm gonna do something a bit different. I am gonna now do convention over configuration. That's the mantra I'm re-adopting for the third or fourth time in my lifetime.
[00:13:12]
YAML feels more like configuration over convention. It's just like, here's every single way you have to configure it. With all the possible options, you have to go onto the Internet and find every last key. And when something doesn't work, you have to figure out why it doesn't work.
[00:13:24]
And it just feels more complicated than it ever needed to be.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops