1 00:00:00,000 --> 00:00:12,240 In this video, you'll get a quick introduction to setting up Ansible for configuration management. 2 00:00:12,240 --> 00:00:16,799 Let's first talk about the requirements. There is a control host. That is where you are going 3 00:00:16,799 --> 00:00:23,080 to push the desired state to the managed machines. And a control host, I would say you send to 4 00:00:23,080 --> 00:00:28,760 a stream or similar, but the control host can be anything nowadays. Ansible control 5 00:00:28,760 --> 00:00:36,520 hosts run successfully on any Linux distributions, on Windows, on Mac OS. But as Ansible is owned 6 00:00:36,520 --> 00:00:44,160 by Red Hat, integration is probably easier on Red Hat based distributions. Also on the 7 00:00:44,160 --> 00:00:49,080 control host, you need to set up hostname resolving for all managed nodes, unless you 8 00:00:49,080 --> 00:00:54,720 want to contact these nodes by IP address. And you generate SSH keys and copy over to 9 00:00:54,720 --> 00:01:01,000 the managed host to make sure that your current Ansible user on the control host can connect 10 00:01:01,000 --> 00:01:06,680 to the managed host without any issues. And next you install the Ansible software. You 11 00:01:06,680 --> 00:01:12,000 create an inventory file, and that's about it. Then on the managed host, you ensure that 12 00:01:12,000 --> 00:01:17,599 Python is installed. That shouldn't be a big deal nowadays, as Python is a part of the 13 00:01:17,599 --> 00:01:24,680 minimal Linux configuration. All Linux distributions, except for the very minimal cloud-based distributions 14 00:01:24,800 --> 00:01:31,839 have Python on board. You need to enable SSH access. And you need to make sure that you 15 00:01:31,839 --> 00:01:36,959 have a user with sudo privileges. If you want to make it easier, and that's what we are 16 00:01:36,959 --> 00:01:43,639 going to do here, that should be a passwordless sudo privileges. But don't worry, in order 17 00:01:43,639 --> 00:01:48,559 to use Ansible, you can do it a secure way as well and make sure that passwords are used 18 00:01:48,559 --> 00:01:54,639 in order to push the configurations. So how do we set up Ansible? Well, on the managed 19 00:01:54,639 --> 00:02:00,400 host, like Ubuntu for instance, you need to make sure that you install open SSH server. 20 00:02:00,400 --> 00:02:05,599 And then on the control host, you install the Ansible core package. You make sure that 21 00:02:05,599 --> 00:02:10,520 you have your host name resolution set up. You generate some SSH keys, copy that key 22 00:02:10,520 --> 00:02:17,080 for the same user to the managed machine, and then you update your inventory. And then 23 00:02:17,080 --> 00:02:22,880 it's time for the first command, which could be Ansible ubuntu minus mping, which is using 24 00:02:22,880 --> 00:02:28,759 the ping module, which is an Ansible module. Ansible is doing its work by using modules. 25 00:02:28,759 --> 00:02:35,600 Minus i inventory is using the inventory. Minus use student is using your student user, 26 00:02:35,600 --> 00:02:40,440 which should be the current user in this example. And minus uppercase K will prompt for the 27 00:02:40,440 --> 00:02:46,759 sudo password. Let me show you. So here I have the Ubuntu host that I want to use, 28 00:02:46,759 --> 00:02:52,240 and I need the IP address. It's giving me lots of information. But here you see information 29 00:02:52,240 --> 00:02:58,919 that is relevant. The IP address ends in 146. Next, I need to make sure that I do my sudo 30 00:02:58,919 --> 00:03:08,479 apt install open SSH dash server. This is an Ubuntu desktop and Ubuntu desktop does 31 00:03:08,479 --> 00:03:14,800 not have open SSH server by default. So make sure you install it. Fortunately, on server 32 00:03:14,800 --> 00:03:21,320 editions, you normally do have SSH installed. And now I'm going to set up my control host. 33 00:03:21,320 --> 00:03:26,600 In order to set up the control host, I need to be student user. I don't have to be the 34 00:03:26,600 --> 00:03:34,380 root user. First, I'm installing the Ansible package using sudo dnf install minus y ansible 35 00:03:34,500 --> 00:03:41,220 core. As a quick check, I'm using Ansible minus minus version, which is showing that this has 36 00:03:41,220 --> 00:03:48,820 installed Ansible version 2.16.14. So Ansible is installed. Next, I'm going to use sudo sh 37 00:03:48,820 --> 00:04:03,539 minus c echo 192.168.29.146. And I'm calling it Ubuntu.example.com short name Ubuntu. And I'm 38 00:04:03,539 --> 00:04:12,820 redirecting this to etc hosts. Let's use double quotes, no need to use single quotes. Now, what 39 00:04:12,820 --> 00:04:18,980 is this command doing? Well, we are running sudo. But the problem is that there's a redirect and 40 00:04:18,980 --> 00:04:25,739 the redirect causes confusion. And that is why I'm using sudo on the command sh minus c, where sh 41 00:04:25,739 --> 00:04:32,220 minus c executes the entire command including the redirect. If ever you want to use composed 42 00:04:32,220 --> 00:04:38,959 commands that have a redirect or a pipe in them, in sudo, it is wise to use sudo sh minus c and the 43 00:04:38,959 --> 00:04:47,579 entire command between double quotes. So as a result, I should be able to ping Ubuntu. So this 44 00:04:47,579 --> 00:04:55,100 proves that I can reach the Ubuntu machine by its name. Now I'm going to generate SSH keys. For this 45 00:04:55,100 --> 00:05:00,299 demo, I want to keep it simple. So I'm using my current sudo enabled user account, which is a 46 00:05:00,299 --> 00:05:07,220 student user. Ubuntu has a student user as well. So I'm using SSH keygen to generate a public private 47 00:05:07,220 --> 00:05:17,500 key pair, and then SSH copy ID to Ubuntu, which is copying my public key over to Ubuntu. I need to 48 00:05:17,500 --> 00:05:26,059 enter the password once. And now we have passwordless authentication on the remote host. 49 00:05:26,579 --> 00:05:35,500 Quick check when I use SSH Ubuntu, I'm on the Ubuntu machine using exit and I'm back. Okay, now I need to 50 00:05:35,500 --> 00:05:44,019 create a so called inventory. Echo Ubuntu greater than greater than inventory. The inventory file for 51 00:05:44,019 --> 00:05:49,660 Ansible identifies all the managed assets. So it's a pretty important file. Without an inventory file, 52 00:05:49,899 --> 00:05:56,899 Ansible only knows localhost. So Ansible doesn't use hostname resolution. When you are going to use 53 00:05:56,899 --> 00:06:03,500 an Ansible command, Ansible uses inventory to find more information about managed hosts. And now I 54 00:06:03,500 --> 00:06:10,500 can use a so called Ansible ad hoc command. Doing that using Ansible Ubuntu minus M ping minus I 55 00:06:10,540 --> 00:06:16,260 inventory. I'm using the ping module. The ping module, in fact, is a Python script that can be 56 00:06:16,260 --> 00:06:23,540 used to ping assets in Ansible. Minus I inventory is telling Ansible to use the inventory file I just 57 00:06:23,540 --> 00:06:31,260 created in my current directory. Minus you student is using the student user, which is my current user 58 00:06:31,260 --> 00:06:37,859 account. And not really necessary here. But let me show you anyway. Minus uppercase K will prompt for 59 00:06:37,859 --> 00:06:46,459 the sudo password at the other side. So there we go. Here is the become password. I'm entering it. And 60 00:06:46,459 --> 00:06:52,540 here we see the result of the Ansible ping module. So what does that mean? Congratulations, you just 61 00:06:52,540 --> 00:06:55,299 successfully ran your first Ansible command.