Introduction to Ansible Transcripts
Lecture: Installing App Dependencies with venv and pip3
0:00 We now have our source code on our web server but nothing is running. So, what we want to do in the next step
0:07 is install our application dependencies with pip into a virtual environment, which provides dependency isolation for Python applications, and then
0:15 stand up our WSGI web server gateway interface server. Once that's done, we can also test out our NGINX configuration.
0:29 Let's take the next step to create our virtual environment install our dependencies with pip and then we'll be ready to set up our WSGI server.
0:38 Head back up into roles/webserver/tasks. Modify main.yml. We're ready to create a new file dependencies.yml.
1:01 Now, we want to make sure we've got a couple of packages installed. One of them Python pip should already be installed
1:06 but we'll add it to our list here, just in case. So, there's no harm in adding a package name as a check to see if it should be installed
1:13 and if it already is installed, it'll just be skipped over. So, we're going to go back and use the ebt module. We need superuser privileges.
1:38 All right, now we want to create a virtual environment. We're going to check to see if it's already created. If it is, we'll avoid this step.
1:57 Now, if it's not created we will create a directory for it. We'll run the command to create a virtual environment.
2:13 And we'll create a new variable for VM directory. Then finally, with our virtual env in place we can use the pip3 command to install the dependencies
2:28 that our application lists into our virtual environment.
2:51 Okay, let's add a venv_dir to our variables. And this will be outside of our git repository directory.
3:09 Okay. Those should be the new tasks that we need our web server to install the application dependencies for our application.