Lab 10 - Multiple Environments¶
Mandatory¶
Split your inventory¶
Create two inventory files for
testandprodUse the same structure, but only use one web server
- Add
web1.<firstname>.labintoprod - Add
web2.<firstname>.labintotest
- Add
Run a ad-hoc command on the hostgroup
webfor both inventory filestestandprodVerify, if the task was executed on the right server
Hint
Use the option -i <inventory-file>
Set some variables¶
- Create a parent group called
prodand add the groupwebanddb - Create a parent group called
testand add the groupwebanddb - Create a variable
envvar: testonly for thetestservers - Create a variable
envvar: prodonly for theprodservers - Create a simple playbook and print out the
envvarfor both inventories - Run the playbook on both inventories
testandprod
Hint
Use the debug module to print out variables.
Hint
Use the -i <inventory-file> option
Change the inventory in ansible.cfg¶
- Make the
testinventory to your default inventory
Create a new role¶
Create a new role
flask_appCreate a new variable
flask_app_versionfortestandprod- value for
prod-> v1.0 - value for
test-> v1.1
- value for
Create a role default variable for
flask_app_versionand set it tomasterCreate 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
webhostgroup - add the
flask_approle
- run only on
Run the playbook on both inventories
testandprodVerify the checkout of the correct version -> Log on the servers, switch into the
/opt/flask_appdirectory and rungit describe --tagsorgit status
Commit your changes¶
- add all files to your git repo and commit it