Lab 12 - Final Lab """""""""""""""""" Mandatory ========= Get an overview --------------- * Checkout the README of this repo and try to figure out, what's needed to run this application. * URL: https://github.com/pstauffer/flask-mysql-app 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 * repo: https://github.com/pstauffer/flask-mysql-app.git * dest: ``/opt/flask_app`` * version: the defined ``flask_app_version`` variable * 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 `_ * url: https://raw.githubusercontent.com/pstauffer/flask-mysql-app/master/students.sql * dest: ``/tmp/students.sql`` * 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) * http://web1.[name].lab:8000 * http://web2.[name].lab:8000 .. 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