Lab 12 - Final Lab

Mandatory

Get an overview

Frontend part

  • Reuse your flask_app role

  • Ensure, the role has a dependency on your python-pip role

  • Install all pip packages, that are listed in the README. (Use the Pip Module)

  • Install all Red Hat specified packages, that are listed in the README. Hint: when Condition

  • Install all Debian specified packages, that are listed in the README. Hint: when Condition

  • Create a task to clone the git repository

  • Create a “version” template file

    • path: /tmp/app-version.txt
    • content: the defined flask_app_version variable
  • Define a database configuration template file

    • path: /etc/dbhost.cfg
    • content: MYSQL_DATABASE_HOST = '{{ groups['db'][0] }}'
  • Add a default variable flask_gunicorn_command with the value gunicorn --pid /tmp/gunicorn.pid --chdir /opt/flask_app --bind 0.0.0.0:8000 --daemon wsgi:app

  • Use the default variable flask_gunicorn_command to start gunicorn via the command module.

Hint

If something went wrong, try to kill the gunicorn process by hand -> ansible -m shell -a "pgrep gunicorn|xargs kill" web -i prod

Backend part

  • Create a role flask_db for the backend part and try to fulfill the requirements

    • install the mysql-server package

    • configure the bind-address in the mysql configuration file /etc/mysql/my.cnf. You can use the module Lineinfile to only replace the bind-address definition. Or just manage the whole file with the template module.

    • define a handler to restart mysql after configuration change.

    • download the database dump with the get_url Module

    • load the mysql dump with the shell command mysql --user=root --password='' < /tmp/students.sql. Also add the options changed_when: false and ignore_errors: true.

    • ensure the mysql service is enabled and started

Playbooks and tests

  • Create a playbook play-db.yml for the database part

    • include the defined flask_db role
    • run only on db hostgroup
  • Create a playbook play-web.yml for the web part

    • include the defined flask_app role
    • run only on web hostgroup
  • Create a master playbook deploy.yml and include both playbooks (1. db, 2. web)

  • Run your playbook deploy.yml for both inventories (test and prod)

  • Test the application (app_version and database entries)

Hint

You should see the version v1.1 and other images on the web2 url

Optional

  • Run the gunicorn command only, if the pid file /tmp/gunicorn.pid does not exists.
  • Use tags
  • Try to split the roles, to make parts more reusable (like gunicorn, git, flask)

Commit your changes

  • add all files to your git repo and commit it