Lab 11 - Solution

Mandatory

Create a new host group

  • Create a new host group for flask_app in both inventories test and prod
# file: test and prod
[flask_app:children]
web
db
  • Change the test and prod host group to use the new hostgroup flask_app
# file: test
[test:children]
flask_app
# file: prod
[prod:children]
flask_app
  • Create the variable flask_app_source only for the flask_app group with the value https://github.com/pstauffer/flask-mysql-app.git
# file: group_vars/flask_app.yml
---
flask_app_source: https://github.com/pstauffer/flask-mysql-app.git

Extend your flask_app role

  • Use the defined flask_app_source variable in your task file for the git checkout
# file: roles/flask_app/tasks/main.yml
    ---
    - name: checkout flask_app
      git:
        repo: '{{ flask_app_source }}'
        dest: /opt/flask_app
        version: '{{ flask_app_version }}'
  • Create a dependency on the already created python-pip role
# file: roles/flask_app/meta/main.yml
---
dependencies:
  - python-pip
  • Run the playbook deploy.yml for both inventories test and prod

    ansible-playbook -i test deploy.yml

    ansible-playbook -i prod deploy.yml

  • Verify the checkout of the correct version

ssh web1.<firstname>.lab
cd /opt/flask_app
git describe --tags
v1.0

ssh web2.<firstname>.lab
cd /opt/flask_app
git describe --tags
v1.1

Commit your changes

  • add all files to your git repo and commit it
git status
git add roles/*
git commit -m 'lab 11'