Introduction to Ansible Transcripts
Chapter: Configuring Servers
Lecture: Installing PostgreSQL

Login or purchase this course to watch this video and the rest of the course contents.
0:00 How are we doing so far on our steps
0:01 to take a look at some of the modules
0:03 that we use in order to configure our server?
0:05 We said that first we were going to provision
0:07 a couple of servers off DigitalOcean, which we did.
0:09 Create a non-root group and user
0:11 that'd be our deployers group and deployer user
0:14 which are set as variables so we could change
0:16 the names if we wanted to.
0:17 We want to harden our server against malicious actors.
0:20 We took just the absolute basic steps of updating
0:23 the system packages, putting in some firewall rules
0:25 locking down the root user so that no one
0:28 can log in directly
0:29 whether it be a password or even with a private key.
0:32 Under the root user they can only log in
0:34 under the deployer user.
0:35 You likely want to take many more steps and do more research
0:38 about how to secure a web server
0:39 but those are just some of the basic steps
0:41 that you're always going to want to take.
0:42 Next we stood up a web server, installed Nginx
0:45 and we wrote the absolute simplest custom
0:47 web server configuration that we could easily expand.
0:50 And which we will expand in the next chapter
0:51 to include a security certificate
0:53 that we can have HTTPS connections.
0:55 To round out the scaffolding for this chapter
0:57 we're going to install and configure the Postgres database.
1:00 And we want to check the database connection
1:02 just do some very basic set up.
1:03 For example, creating a database and creating
1:05 a separate Postgres user for that database.
1:08 Let's give this a try.
1:10 We're back in the base directory
1:11 of our server config project
1:14 and let's go under roles/database
1:17 and then under tasks.
1:19 Now we already have a couple YAML files here
1:21 because we set up the firewall roles
1:25 specifically for Postgres access
1:27 only on our database server.
1:28 Go back under main.yml.
1:31 And we're going to include a new file
1:33 we'll just call this one postgresql.yml
1:37 Save that and now let's create this file.
1:50 We'll start out by installing the system packages
1:52 that we need for Postgres and if we wanted
1:54 to run a Python application.
2:04 We'll use the apt module again and remember
2:06 and we're going to list out a bunch of system packages
2:08 but remember these will only get installed once
2:10 because Ansible always goes and checks
2:12 to make sure that those packages are installed
2:14 and if they are already installed
2:15 it's not going to do it over again.
2:17 So it saves time on subsequent playbook routes.
2:23 The name of the package is specified as a token.
2:28 And the items that will populate that token
2:33 are the following packages.
2:45 And we'll need superuser privileges
2:47 in order to install this.
2:49 One thing to take note of here
2:50 it's really easy to make a typo in a package name
2:53 so always check to make sure that you've typed
2:55 in the appropriate packages.
2:56 I actually just realized I had a h
2:58 where there should be a g
2:59 which would cause this task to fail.
3:01 Now this looks good. We want the psycopg2 package.
3:04 We could save this, should be ready to run.
3:06 Head back up into the base project directory.
3:12 Let's give our playbook a try.
3:29 Looks good.
3:30 We should have these packages installed
3:31 and now we can customize our Postgres configuration.