Milestone: A Git Repsoitory#

In this milestone you will get ready to rebuild your application using Ansible and Terraform.

Labs#

In class we will do a number of steps to get ready for the final version of our project.

  1. Say goodbye to your devbox (and recreate a fresh one). Make sure to review the steps in your document.

    1. Connect your existing service account to the new devbox

  2. Create a separate GCP project just for the next phase of the class. Do the following in the new project:

    1. Add your existing service account as a principal with owner access

    2. Create a new VM (don’t associate the SA with it)

  3. Create a local GIT repository and push it to GitHub

  4. Configure Ansible and use it to install packages on your new instance

Create a Git Repo#

Your new devbox will be just for development. In your devbox home directory create a new Git repository:

git config --global init.defaultBranch main
git config --global user.name "Your Name"
git config --global user.email "Your GitHub Email"
git init cis-91 

That will create a CIS-91 directory. Do the next steps in that directory.

Ansible Setup#

Install Ansible and the necessary plugins:

sudo apt install python3-pip
pip install --upgrade pip wheel
source ~/.profile 
pip install ansible requests google-auth

Place this into a file called ~/.ansible.cfg:

[defaults]
host_key_checking = False

Place this YAML into a file called gcp.yaml:

plugin: gcp_compute
projects:
  - your-project-here
auth_kind: machineaccount
keyed_groups:
  - prefix: gcp
    key: labels
  - prefix: tags
    key: tags

Test your inventory:

ansible-inventory --list -i gcp.yaml

If you see your new project box, proceed to the next step. Place this into a file called playbook.yaml:

- hosts: all
  name: Install Apache and PHP
  become: yes
  tasks:
    - name: Install packages 
      ansible.builtin.apt:
        update_cache: yes
        cache_valid_time: 3600
        name:
          - apache2
          - php

Execute your playbook with the command:

ansible-playbook -i gcp.yaml playbook.yaml

First Git Commit#

When you have Ansible working save your work by making a Git commit and pushing your repo up to GitHub.

Documentation#

Document your steps and post them to the class discussion form. Your post should include a link to your GitHub repository.