nginx/tasks/froxlor_configure_vhost.yml

146 lines
3.5 KiB
YAML

---
- debug:
var: loop_domain
tags:
- froxlor
when:
- use_froxlor is defined
- use_froxlor
- not loop_domain in know_froxlor_domain
- name: "Get domain info"
ansible.builtin.uri:
url: "{{ froxlor_url }}/api.php"
method: "POST"
headers:
Content-Type: "application/json"
Authorization: "Basic {{ froxlor_token }}"
body: "{\"command\":\"SubDomains.get\", \"params\": {\"domainname\": \"{{ loop_domain }}\"} }"
status_code: 200
body_format: "json"
register: domain_info
delegate_to: localhost
when:
- use_froxlor is defined
- use_froxlor
- not loop_domain in know_froxlor_domain
tags:
- froxlor
- debug:
var: domain_info["json"]["data"]
verbosity: 2
when:
- use_froxlor is defined
- use_froxlor
- not loop_domain in know_froxlor_domain
tags:
- froxlor
- name: show templating results
ansible.builtin.debug:
msg: "{{ lookup('ansible.builtin.template', 'templates/vhosts/partials/froxlor_upstream.j2') }}"
verbosity: 2
when:
- use_froxlor is defined
- use_froxlor
- not loop_domain in know_froxlor_domain
tags:
- froxlor
- name: Set var
ansible.builtin.set_fact:
upstream: "{{ lookup('ansible.builtin.template', 'templates/vhosts/partials/froxlor_upstream.j2') }}"
tags:
- froxlor
when:
- use_froxlor is defined
- use_froxlor
- not loop_domain in know_froxlor_domain
- name: Set var
ansible.builtin.set_fact:
#item: "{{ lxc_item_redirect | combine( { upstream: upstream } ) }}"
item: "{{ lxc_item_redirect }}"
tags:
- froxlor
when:
- use_froxlor is defined
- use_froxlor
- not loop_domain in know_froxlor_domain
- name: "Add redirect Vhost"
template:
src: "vhosts/redirect.j2"
dest: "/etc/nginx/sites-available/froxlor_{{ loop_domain }}-80.conf"
notify:
- Reload Nginx
tags:
- froxlor
when:
- use_froxlor is defined
- use_froxlor
- not loop_domain in know_froxlor_domain
- name: "Enable redirect vhost"
file:
src: "/etc/nginx/sites-available/froxlor_{{ loop_domain }}-80.conf"
dest: "/etc/nginx/sites-enabled/froxlor_{{ loop_domain }}-80.conf"
state: link
tags:
- froxlor
when:
- use_froxlor is defined
- use_froxlor
- not loop_domain in know_froxlor_domain
notify:
- Reload Nginx
- name: "Create certificate"
shell: "certbot certonly --non-interactive --webroot --email {{ nginx_letsencrypt_email }} --agree-tos --webroot-path=/var/www/letsencrypt -d {{ loop_domain }} --expand --key-type ecdsa --elliptic-curve secp384r1;"
tags:
- froxlor
when:
- use_froxlor is defined
- use_froxlor
- not loop_domain in know_froxlor_domain
- name: Set var
ansible.builtin.set_fact:
item: "{{ lxc_item_proxy }}"
tags:
- froxlor
when:
- use_froxlor is defined
- use_froxlor
- not loop_domain in know_froxlor_domain
- name: "Add proxy vhost"
template:
src: "vhosts/proxy.j2"
dest: "/etc/nginx/sites-available/froxlor_{{ loop_domain }}-443.conf"
notify:
- Reload Nginx
tags:
- froxlor
when:
- use_froxlor is defined
- use_froxlor
- not loop_domain in know_froxlor_domain
- name: "Enable proxy vhost"
file:
src: "/etc/nginx/sites-available/froxlor_{{ loop_domain }}-443.conf"
dest: "/etc/nginx/sites-enabled/froxlor_{{ loop_domain }}-443.conf"
state: link
tags:
- froxlor
when:
- use_froxlor is defined
- use_froxlor
- not loop_domain in know_froxlor_domain
notify:
- Reload Nginx