Ansible workflow - Torniojaws/vortech-backend GitHub Wiki
When you launch Ansible, it is for example with:
ansible-playbook deploy/site.yml -i deploy/inventory/dev --connection=local
What you tell is:
- Run the Ansible playbook in
deploy/site.ymland process it as-is - Use the
inventorydefined in filedeploy/inventory/dev - Run all the commands locally instead of a remote server
An Inventory lists where the Ansible commands will be run in. It could be used to deploy to multiple servers (server1.myhost.com, server2.myhost.com, etc) all at once. You also define the group in the inventory file. The group can be used to define an environment, eg.
# file: deploy/inventories/dev
[development] <-- This is the group
localhost <-- The URI that will be updated by Ansible
This would automatically read whatever is defined in group_vars/development[.yml], where in turn you can define group-specific variables. The variables can then be used to control the flow in the playbooks, for example to only run a certain play in production or development.
# file: deploy/group_vars/production.yml
---
env: prod
# in a playbook
tasks:
- shell: echo "This only runs in production"
when: env == "prod"
There is also host_vars which have higher priority than group_vars, and they apply to specific hosts (URIs).