Lab 10 - Multiple Environments """""""""""""""""""""""""""""" Mandatory ========= Split your inventory -------------------- * Create two inventory files for ``test`` and ``prod`` * Use the same structure, but only use one web server * Add ``web1..lab`` into ``prod`` * Add ``web2..lab`` into ``test`` * Run a ad-hoc command on the hostgroup ``web`` for both inventory files ``test`` and ``prod`` * Verify, if the task was executed on the right server .. hint:: Use the option ``-i `` Set some variables ------------------ * Create a parent group called ``prod`` and add the group ``web`` and ``db`` * Create a parent group called ``test`` and add the group ``web`` and ``db`` * Create a variable ``envvar: test`` only for the ``test`` servers * Create a variable ``envvar: prod`` only for the ``prod`` servers * Create a simple playbook and print out the ``envvar`` for both inventories * Run the playbook on both inventories ``test`` and ``prod`` .. hint:: Use the ``debug`` module to print out variables. .. hint:: Use the ``-i `` option Change the inventory in ansible.cfg ----------------------------------- * Make the ``test`` inventory to your default inventory Create a new role ----------------- * Create a new role ``flask_app`` * Create a new variable ``flask_app_version`` for ``test`` and ``prod`` * value for ``prod`` -> v1.0 * value for ``test`` -> v1.1 * Create a role default variable for ``flask_app_version`` and set it to ``master`` * Create a task to checkout the git repo (see `Git Module `_) * https://github.com/pstauffer/flask-mysql-app.git * checkout the version defined in the variable ``flask_app_version`` * destination path should be ``/opt/flask_app`` * Create a new playbook ``deploy.yml`` * run only on ``web`` hostgroup * add the ``flask_app`` role * Run the playbook on both inventories ``test`` and ``prod`` * Verify the checkout of the correct version -> Log on the servers, switch into the ``/opt/flask_app`` directory and run ``git describe --tags`` or ``git status`` Commit your changes ------------------- * add all files to your git repo and commit it