TL;DR:
Variables prefixed with app_ are used by Apps and Sysapps
and have some extra customization via ALB Strategies.
These are key elements that form a single dictionary (think object) for the
alb_apps (list of dictionaries) and alb_sysapps (list of dictionaries).
Quick example:
alb_apps:
- app_uid: "static-files"
app_domain: "assets.example.org"
app_root: "/var/www/html"
app_alb_strategy: "files-local"
- app_uid: "minio"
app_domain: "minio.example.org"
app_alb_proxy: "http://localhost:9091"
app_alb_strategy: "proxy"
alb_sysapps:
- app_uid: "consul"
app_domain: "consul..nip.io"
app_alb_strategy: "proxy"
app_alb_proxy: "http://127.0.0.1:8500"
New on v0.8.6-alpha: internally ALB will merge alb_sysapps_alb +
alb_sysapps_always + alb_sysapps and alb_app_always + alb_apps. Ansible
default behavior when the same variable is defined default and then some hosts
also specify the variable is override. To make it easier for who want some
apps/sysapps be on all nodes on a datacenter (and to avoid you use advanced
features like hash_behaviour or implement plugins like
leapfrogonline/ansible-merge-vars)
we suggest use as convention alb_sysapps_always and alb_app_always.
Note: as v0.8.x, this section still maybe not reflex all implementation, but as here as a plan of action (fititnt, 2019-12-04 17:27 BRT)
String, [a-zA-Z0-9\-\_]
:, ;, UTF-8 characters (requires you system to support)/, \, control character (NUL \0, LF \n, …)alb_apps and alb_sysapps can reuse same app_id)hello-world, hello_worldInternaly, AP-ALB use app_uid common name for configutation files (like
/opt/alb/apps/.conf), default logs directory, default data
diretory, internal aliases for which load balance and more.
present, absentapp_state defaults to present, so you did not need to define. If you want
remove one app, it’s configurations rules, log files, etc, you should at least
once re-run one time with the same app_uid and app_state: absent for each
node. After this, you can remove referentes to the old app/sysapp.
Note: implementators should not automaticaly remove backups based only on this configutation.
app_uidString, Regex String
hello-world.example.org, hello-world.*, "hello-world..nip.io"Most app_type expect at least one main domain so the the AP-ALB will know what
to do when a request comes in.
String, Regex String# Empty list app_domain_extras: [] # Please avoid using 'app_domain_extras: ' without defined itens and ': []' at the end# List with 3 extra domains app_domain_extras: - "hello-world.example.org" - "hello-world.*" - "hello-world..nip.io"
Use this to add extra domains to app_domain.
alb_forcedebug(If defined), alb_default_app_forcedebug(If defined)yes, true, no, falseMark one app in special to show more information, useful for debug. The information depends on the app_type implementation.
false, alb_default_app_forcehttps(If defined)yes, true, no, falseIf true, acessing HTTP port will redirect 301 to the app_domain.
This option is one alternative to not use Ansible Host vars or Ansible Group
Vars to define what Application run where. So you could have only one alb_apps
alb_sysapps for the entire cluster (or more than one cluster if using more
than one datacenter).
@TODO: implement this feature (fititnt, 2019-12-04 22:43 BRT)
alb_default_app_index(If defined)index.html index.phpalb_default_app_root(If defined)/var/html/www/String# Empty app_tags app_domain_extras: [] # Please avoid using 'app_tags: ' without defined itens and ': []' at the end# List with 3 extra domains app_tags: - "my-tag-1" - "another-tag" - ""
app_data_* are one way to document specific applications that you care about
make backups, or export/import from one node to another. The typical scenario
is you document, at App/Sysapp level, what a different AP-ALB node should have
to be fully operational.
As AP-ALB v0.8.2, this Role alone does not implement the full logistics of how to make the import/export/backup but you are encoraged to use these variables as one way to document or reuse future implementations.
Also keep in mind that even if AP-ALB implement these features, is likely that you would still need configure external services to store backups, since the priority here would be sincronize 2 nodes that, for example, do not have a shared (and often sloooow) filesystem.
app_data_directories: - "/var/www/myapp"
app_data_files: - "/var/lib/rancher/k3s/server/node-token" - "/var/lib/rancher/k3s/server/db/state.db.bak"
"/delete-temporary-files.yml""/database-dump-to-file.yml""/populate-database-from-database-dump.yml""/install-requeriments-for-this-app-if-already-not-exist.yml"app_healthcheck_* additional to the default one/app-health-check@TODO: this is a draft (fititnt, 2020-01-05 09:33 BRT)
/app-health-check@TODO: this is a draft (fititnt, 2020-01-05 09:33 BRT)
Some string that health page have, Hello to my frontpage@TODO: this is a draft (fititnt, 2020-01-05 09:33 BRT)
app_hook_after/hooks/app-static-html.yml, /ad-hoc-alb/hooks/debug.yml, /ad-hoc-alb/hooks/example/example_app_hook_after.ymlYou can execute custom tasks specific to one app after deployed.
app_hook_before/hooks/app-static-html.yml, /ad-hoc-alb/hooks/debug.yml, /ad-hoc-alb/hooks/example/example_app_hook_before.ymlYou can execute custom tasks specific to one app before deployed.
app_hook_onchange (draft)Equivalent of app_hook_after, but will only run if the alb
app was changed.
app_hook_[alb_play]_*app_hook_infra_after, app_hook_infra_before, app_hook_infra_onchange, app_hook_backup_before/hooks/app-static-html.yml, /ad-hoc-alb/hooks/debug.yml, /ad-hoc-alb/hooks/example/example_app_hook_after.ymlAll options from app_hook_* are avalible to app_hook_[alb_play]_*. The main
difference here is that [alb_play] act as one way to namespace your hooks.
The special variable alb_play could be hardcoded on your playbook or defined
as command line variable (e.g.
ansible-playbook -i hosts.yml my-playbook.yml -e="alb_play=infra") so only
when this variable is defined, these hooks will be run.
@TODO: this explain some workarounds to archive this https://github.com/ansible/ansible/issues/17324
String or undefined or null
files-local, hello-world, proxy, raw, nullThis option define what base OpenResty/NGinx template will be used as base for process all other variables.
As version v0.8.1-alpha, this app_backup_strategy still not implemented.
As version v0.8.1-alpha, this app_ha_strategy still not implemented.
As version v0.8.7-beta, this app_healthcheck_strategy still not implemented.
As version v0.8.1-alpha, this app_nlb_strategy still not implemented.
String equivalent to ``app_alb_hosts: - "ap_delta" - "ap_echo"
@TODO consider implement this planned (but not fully usable) feature as additional alternative to Ansible Inventory (fititnt, 2019-12-05 19:17 BRT)
proxyhttp://127.0.0.1:8080,proxyapp_alb_proxy_defaults enable defaults inside the main proxy location block, like
these ones:
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
# ...
}
Disable if you is having issues or what to make full customization with
app_alb_proxy_raw. If you are OK with the defaults, use app_alb_proxy_params
to just append new values
proxy//, = /, ~ \.phpproxyalb_default_app_alb_proxy_params(If defined)alb_apps: # Laravel example https://laravel.com/docs/deployment - app_uid: "laravel-site" - app_domain: ".example.com" - app_alb_strategy: "proxy" - app_alb_proxy_location: "~ \.php$" - app_alb_proxy: "unix:/var/run/php/php7.4-fpm.sock" - app_alb_proxy_params: - fastcgi_index: "index.php" - fastcgi_param: "SCRIPT_FILENAME $realpath_root$fastcgi_script_name" - include: "fastcgi_params"
alb_apps:
- app_uid: "hello-world-minimal"
app_domain: "hello-world-minimal..nip.io"
app_alb_strategy: "minimal"
app_alb_raw_file: "templates/example_app_alb_raw_file.conf.j2"
app_alb_raw: >
charset_types application/json;
default_type application/json;
location = /status {
stub_status;
allow all;
}
location = /ping {
access_log off;
return 200 "pong\n";
}
location = / {
content_by_lua_block {
local cjson = require "cjson"
ngx.status = ngx.HTTP_OK
ngx.say(cjson.encode({
msg = "Hello, hello-world-minimal! (from app_alb_raw)",
status = 200
}))
}
}
See https://yaml-multiline.info if having issues with identation.
You can use app_alb_raw_file as alternative.
templates/example_app_alb_raw_file.conf.j2Example of templates/example_app_alb_raw.conf.j2 content:
# File: github.com/fititnt/ansible-linux-ha-cluster/templates/example_app_alb_rawfile.conf.j2
# This file is just one example of using app_alb_raw_file instead of
# app_alb_raw template string
# With app_alb_raw you can't use item.app_uid variable, for example, but here
# you can
location / {
content_by_lua_block {
local cjson = require "cjson"
ngx.status = ngx.HTTP_OK
ngx.say(cjson.encode({
msg = "Hello, ! (from app_alb_raw_file)",
status = 200
}))
}
}
Deprecated. Please use app_raw_alb and/or app_alb_raw_file
Before AP-ALB v.0.8.x alb_apps[n]app_alb_strategy has default value of
hello-word (and before that, files-local).
Now, value of app_alb_strategy is ommited, the alp_apps / alb_sysapps will be ignored by OpenResty.
The reason for this is allow on future have apps that can exist only for other reasons (for example, for NLB/HAProxy, or for Backup tasks). This also means that a same app group could have variables reused for different strategies
@TODO write small paragraph about AP-ALB and Azure Load Balancer (fititnt, 2019-12-15 06:44 BRT)
@TODO write small paragraph about AP-ALB and AWS Application Load Balancers Listeners (fititnt, 2019-12-15 06:44 BRT)
@TODO write small paragraph about AP-ALB and AWS Google Cloud Load Balancing (fititnt, 2019-12-15 06:44 BRT)