The playbook file would be:
- hosts: stagingwebservers
gather_facts: False
vars:
- server_port: 8080
tasks:
- name: install nginx
apt: pkg=nginx state=installed update_cache=true
- name: serve nginx config
template: src=../files/flask.conf dest=/etc/nginx/conf.d/
notify:
- restart nginx
handlers:
- name: restart nginx
service: name=nginx state=restarted
- name: restart flask app
service: name=flask-demo state=restarted
...
In the above playbook, we are fetching all hosts of stagingwebservers group for executing these tasks. The first task is to install Nginx and then configure it. We are also taking a flask server for reference. In the end, we also defined handlers so that in case the state changes it will restart Nginx. After executing the above playbook we can verify whether Nginx is installed or not.
ps waux | grep nginx