Project 1: Package an Application#
In this project you’ll use Ansible and Terraform to package the work you did in the Install Software Three Ways lab. In the last lab you modified your VM manually, which is important for learning how to get things working, but can’t be quickly copied and redone.
Use the code you develop in
playbook.yaml as a start for this project and will be the basis for future projects.
In your git repository, create copy the
base directory to create a new directory for this project.
$ cp -R base project1 $ cd project1
You should have performed
terraform destroy in
base before making a copy
Configure the ACL#
main.tf file update the allowed ports to include only:
playbook.yaml file already has a play that installs the
python3-venv packages. Add the following packages to the list:
Create a Custom HTML File#
Here’s some HTML. Update it with your name and copy paste it into a file called
index.html in the same directory as
<!DOCTYPE html> <html> <body> <h1>Welcome to my CIS-91 project!</h1> <p>Your name here.</p> </body> </html>
Write a Play to Install
Ansible can copy files from the local machine to the target. You can find the full documentation in the documentation of ansible.builtin.copy. Add the following task to your existing ansible play.
- name: Copy file with owner and permissions ansible.builtin.copy: src: index.html dest: /var/www/html/index.html owner: www-data group: www-data mode: '0644'
Test your Work#
Start by using Terraform to create your infrastructure:
$ terraform init $ terraform apply
Now use Ansible to apply the VM configuration:
$ ansible-playbook --private-key ~/.ssh/google_compute_engine -i ../inventory.gcp.yaml playbook.yaml
You should see your custom HTML by directing your browser to your IP address.
Commit and Push Your Changes#
In class I demonstrate committing your work using the Cloud Shell Editor and vscode. You can also do it on the command line:
$ git add index.html main.tf playbook.yaml $ git commit -m "First commit of lab 07" $ git push
Turn in the following:
The URL of your GitHub repo (I will browse there and look at your
The IP address of your project so I can visit your page.