Lab 11 - Solution¶
Mandatory¶
Create a new host group¶
- Create a new host group for
flask_appin both inventoriestestandprod
# file: test and prod
[flask_app:children]
web
db
- Change the
testandprodhost group to use the new hostgroupflask_app
# file: test
[test:children]
flask_app
# file: prod
[prod:children]
flask_app
- Create the variable
flask_app_sourceonly for theflask_appgroup with the valuehttps://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_sourcevariable 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-piprole
# file: roles/flask_app/meta/main.yml
---
dependencies:
- python-pip
Run the playbook
deploy.ymlfor both inventoriestestandprodansible-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'