QuickstartΒΆ
If we have Ansible 2.9 or newer installed, we can download and install the NGINX Unit Ansible Collection with just one command:
$ ansible-galaxy collection install steampunk.unit
With the collection in place, we are just one Ansible
playbook
away from
deploying a minimalistic python application:
---
- name: Install and run NGINX Unit
hosts: unit_hosts
become: true
tasks:
- name: Install Unit
include_role:
name: steampunk.unit.install
- name: Create a directory for our application
file:
path: /var/www
state: directory
- name: Copy application
copy:
src: files/wsgi.py
dest: /var/www/wsgi.py
mode: "644"
- name: Add application config to Unit
steampunk.unit.python_app:
name: sample
module: wsgi
path: /var/www
- name: Expose application via port 3000
steampunk.unit.listener:
pattern: "*:3000"
pass: applications/sample
When we run it, Ansible will:
install and run the Unit server,
copy our
python application
to the remote host, andinstruct Unit to start passing the requests on port 3000 to our application.
Now, before we can run this playbook, we need to prepare an inventory file.
The inventory should contain an unit_hosts group becuse our playbook expects
to find target hosts there. A
minimal inventory
with
a singlehosts will look somewhat like this:
all:
children:
unit_hosts:
hosts:
192.168.50.4:
Replace the IP addresses with your own and make sure you can ssh into the host. If you need help with building your inventory file, consult official documentation on inventory.
All that we need to do now is to run the playbook:
$ ansible-playbook -i inventory.yaml playbook.yaml
And in a minute or so, things should be ready to go. And if we now visit http://192.168.50.4:3000 (replace that IP address with the address of your backend), we should be greeted by our application. If no firewall is in a way, of cource ;)