62 lines
1.6 KiB
YAML
62 lines
1.6 KiB
YAML
- name: Install prerequisites for OpenResty
|
|
apt:
|
|
name:
|
|
- curl
|
|
- gnupg
|
|
- apt-transport-https
|
|
state: present
|
|
update_cache: yes
|
|
|
|
- name: Import OpenResty GPG key
|
|
command: >-
|
|
bash -c 'curl -fsSL https://openresty.org/package/pubkey.gpg | gpg --dearmor -o /usr/share/keyrings/openresty.gpg'
|
|
args:
|
|
creates: /usr/share/keyrings/openresty.gpg
|
|
|
|
- name: Add OpenResty apt repository
|
|
apt_repository:
|
|
repo: "deb [signed-by=/usr/share/keyrings/openresty.gpg] http://openresty.org/package/ubuntu jammy main"
|
|
filename: openresty
|
|
state: present
|
|
|
|
- name: Install OpenResty
|
|
apt:
|
|
name: openresty
|
|
state: present
|
|
update_cache: yes
|
|
|
|
- name: Ensure sites-available directory exists
|
|
file:
|
|
path: /usr/local/openresty/nginx/conf/sites-available
|
|
state: directory
|
|
|
|
- name: Deploy nginx configuration
|
|
template:
|
|
src: nginx.conf.j2
|
|
dest: /usr/local/openresty/nginx/conf/nginx.conf
|
|
notify: Restart OpenResty
|
|
|
|
- name: Deploy vhost configurations
|
|
template:
|
|
# Use item.template if provided; otherwise default to the unified site template
|
|
src: "{{ item.template | default('site.conf.j2') }}"
|
|
dest: "/usr/local/openresty/nginx/conf/sites-available/{{ item.name }}.conf"
|
|
loop: "{{ domain | default([]) }}"
|
|
notify: Restart OpenResty
|
|
|
|
- name: Enable and start OpenResty
|
|
systemd:
|
|
name: openresty
|
|
enabled: yes
|
|
state: started
|
|
|
|
- name: Verify OpenResty core API
|
|
shell: |
|
|
curl -fsS -X POST http://127.0.0.1/api/askai \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"question":"你好"}'
|
|
register: openresty_verify
|
|
retries: 5
|
|
delay: 3
|
|
until: openresty_verify.rc == 0
|