2017-02-12
Builder Bob said that whanApp requires some special config for each environment so lets introduce a group variable file per environment
▾ inventory/
▾ dev/
▾ group_vars/
WhanApp.yaml
hosts
▾ prod/
▾ group_vars/
WhanApp.yaml
hosts
▸ roles/
▸ files/
▾ templates/
whanApp.json.j2
whanApp.yaml
the WhanApp.yaml
file is a simple yaml file with 1 variable
with the same name as the group we defined for the app
---
appUrl: https://dev.whanApp.com
for dev and
---
appUrl: https://whanApp.com
for prod
the whanApp.yaml
playbook now looks like this
---
- hosts: nodejsHosts
become: true
roles:
- nodejs
- hosts: WhanApp
become: true
tasks:
<..snip..>
- name: stamp out the config file
template: src=whanApp.json.j2 dest=/opt/whanApp/whanApp.json
- name: restart whanApp
service: name=whanApp state=restarted
referring to devdocs.io for the details…
template
is a [take some variables and stamp out a specific copy for this host] module{
"environment": "{{appUrl}}"
}
and the jinja2 template engine takes the variable from the inventory’s WhanApp.yaml
file
and places the value of appUrl
into the json file
now with the GSD list complete, you hook up the playbook’s execution with bob’s ci server