1 00:00:06,920 --> 00:00:10,100 - In this video, I will tell you about ansible.cfg, 2 00:00:10,100 --> 00:00:11,770 a convenient configuration file 3 00:00:11,770 --> 00:00:13,830 that helps you to set some default values 4 00:00:13,830 --> 00:00:16,853 for your current product or for all of your system. 5 00:00:18,380 --> 00:00:21,250 So when you are managing assets with Ansible, 6 00:00:21,250 --> 00:00:24,470 you will always need to provide different settings. 7 00:00:24,470 --> 00:00:27,290 And these settings can be provided at different levels. 8 00:00:27,290 --> 00:00:29,000 You can put them on the command line. 9 00:00:29,000 --> 00:00:31,105 That is what we have been doing so far. 10 00:00:31,105 --> 00:00:33,130 You can put them in playbooks, 11 00:00:33,130 --> 00:00:34,850 which you will learn about later, 12 00:00:34,850 --> 00:00:37,410 or in the ansible.cfg. 13 00:00:37,410 --> 00:00:40,360 If you are going to work with ansible.cfg, 14 00:00:40,360 --> 00:00:42,900 a default ansible.cfg is provided 15 00:00:42,900 --> 00:00:46,188 in etc/ansible/ansible.cfg. 16 00:00:46,188 --> 00:00:49,600 But you can also create ansible.cfg files 17 00:00:49,600 --> 00:00:52,070 in project directories. 18 00:00:52,070 --> 00:00:55,150 Be aware that if you create an ansible.cfg file 19 00:00:55,150 --> 00:00:57,280 in the project directory, 20 00:00:57,280 --> 00:00:59,930 then that file will always be used. 21 00:00:59,930 --> 00:01:02,750 And if that file exists, 22 00:01:02,750 --> 00:01:05,620 the settings in etc/ansible/ansible.cfg 23 00:01:05,620 --> 00:01:07,223 are not considered at all. 24 00:01:08,280 --> 00:01:10,950 So settings that are made at a more specific level 25 00:01:10,950 --> 00:01:13,593 will always overwrite the generic settings. 26 00:01:14,540 --> 00:01:19,140 Now, let me demonstrate how to use an ansible.cfg 27 00:01:19,140 --> 00:01:21,270 by looking at the default configuration, 28 00:01:21,270 --> 00:01:23,170 but also by looking at an example 29 00:01:23,170 --> 00:01:25,523 from the course Git Repository. 30 00:01:27,080 --> 00:01:29,596 So to start with, I would like to show you 31 00:01:29,596 --> 00:01:33,203 etc/ansible/ansible.cfg, 32 00:01:34,040 --> 00:01:35,690 which is a configuration file 33 00:01:35,690 --> 00:01:38,540 in which you can find all the different parameters. 34 00:01:38,540 --> 00:01:41,080 And there's a lot of parameters. 35 00:01:41,080 --> 00:01:44,430 As you can see, 490 lines in total. 36 00:01:44,430 --> 00:01:47,640 And this is what you can do. 37 00:01:47,640 --> 00:01:50,070 I would like to show you parameters that matter, 38 00:01:50,070 --> 00:01:55,070 but first ansible --version. 39 00:01:55,940 --> 00:01:58,290 Ansible --version is showing you 40 00:01:58,290 --> 00:02:01,455 which configuration file is currently used. 41 00:02:01,455 --> 00:02:05,710 Now we are going to access the course Git Repository. 42 00:02:05,710 --> 00:02:10,710 Before I can, I need sudo dnf install -y git 43 00:02:13,160 --> 00:02:16,263 because that package is not available by default. 44 00:02:17,460 --> 00:02:19,890 And then I can use git clone 45 00:02:19,890 --> 00:02:24,890 https://github.com/sandervanvugt/ansiblecvc. 46 00:02:30,670 --> 00:02:34,063 That's short for Ansible complete video course. 47 00:02:35,230 --> 00:02:40,230 And now if we get into this Ansible CVC, 48 00:02:40,840 --> 00:02:45,160 we see different directories. 49 00:02:45,160 --> 00:02:48,480 Now the thing that matters is the ansible.cfg. 50 00:02:48,480 --> 00:02:49,470 What is that? 51 00:02:49,470 --> 00:02:51,930 Well, that is a configuration file that contains 52 00:02:51,930 --> 00:02:53,980 all the settings that we need. 53 00:02:53,980 --> 00:02:55,350 This is kind of minimal. 54 00:02:55,350 --> 00:02:57,070 So we have a default section. 55 00:02:57,070 --> 00:03:00,180 In a default section, we identified the default options, 56 00:03:00,180 --> 00:03:02,350 including inventory set to inventory, 57 00:03:02,350 --> 00:03:04,520 or remote user set to ansible, 58 00:03:04,520 --> 00:03:06,420 host key checking is false. 59 00:03:06,420 --> 00:03:08,030 You remember the host key checking 60 00:03:08,030 --> 00:03:11,120 that was a failure because of the SSH host keys? 61 00:03:11,120 --> 00:03:12,470 Host key checking is false 62 00:03:12,470 --> 00:03:15,173 makes sure that we won't see that failure anymore. 63 00:03:16,040 --> 00:03:17,400 Inventory is inventory 64 00:03:17,400 --> 00:03:20,520 is looking for a local file with the name inventory. 65 00:03:20,520 --> 00:03:22,330 Remote user is ansible 66 00:03:22,330 --> 00:03:24,880 is expecting a remote user 67 00:03:24,880 --> 00:03:27,140 with the name Ansible to be present. 68 00:03:27,140 --> 00:03:29,690 And then we have privilege escalation 69 00:03:29,690 --> 00:03:32,200 where we set becomes true. 70 00:03:32,200 --> 00:03:33,150 This is what makes it. 71 00:03:33,150 --> 00:03:35,530 We don't have to use -B anymore. 72 00:03:35,530 --> 00:03:37,765 Become method is sudo, become user is root, 73 00:03:37,765 --> 00:03:40,290 and become ask pass is false. 74 00:03:40,290 --> 00:03:42,742 We are not going to prompt for a become password 75 00:03:42,742 --> 00:03:44,803 because this assumes 76 00:03:44,803 --> 00:03:49,803 that password-less privilege escalation is possible. 77 00:03:50,010 --> 00:03:54,240 Now let's run this commands and what is going to happen? 78 00:03:54,240 --> 00:03:56,020 Well, you can see all the parameters 79 00:03:56,020 --> 00:04:00,390 as defined in the ansible.cfg are applied automatically. 80 00:04:00,390 --> 00:04:01,992 So I don't need to specify anything 81 00:04:01,992 --> 00:04:04,180 on the command line anymore. 82 00:04:04,180 --> 00:04:06,680 But hey, what is happening if you would specify 83 00:04:06,680 --> 00:04:07,880 it on the command line? 84 00:04:07,880 --> 00:04:11,030 Well easy, then the command line will always win. 85 00:04:11,030 --> 00:04:13,210 That's a generic rule in Ansible, 86 00:04:13,210 --> 00:04:16,103 the most specific setting will always win.