nginx/tasks/froxlor_vhost.yml

114 lines
2.4 KiB
YAML

---
- name: Check if froxlor_domain.json exist
stat:
path: /etc/nginx/froxlor_domain.json
register: stat_result
when:
- use_froxlor is defined
- use_froxlor == True
tags:
- froxlor
- name: Make file if not exist
ansible.builtin.copy:
content: "[]"
dest: /etc/nginx/froxlor_domain.json
when:
- not stat_result.stat.exists
- use_froxlor is defined
- use_froxlor == True
tags:
- froxlor
- name: "Get all domains"
ansible.builtin.uri:
url: "{{ froxlor_url }}/api.php"
method: "POST"
headers:
Content-Type: "application/json"
Authorization: "Basic {{ froxlor_token }}"
body: '{"command":"SubDomains.listing"}'
status_code: 200
body_format: "json"
register: froxlor_domains
delegate_to: localhost
when:
- use_froxlor is defined
- use_froxlor == True
tags:
- froxlor
- debug:
var: froxlor_domains["json"]["data"]
verbosity: 2
when:
- use_froxlor is defined
- use_froxlor == True
tags:
- froxlor
- name: Get know domain
set_fact:
know_froxlor_domain: "{{ lookup('file','/etc/nginx/froxlor_domain.json') | from_json }}"
when:
- use_froxlor is defined
- use_froxlor == True
tags:
- froxlor
- name: Create a domain list
set_fact:
domains: []
delegate_to: localhost
when:
- use_froxlor is defined
- use_froxlor == True
tags:
- froxlor
- name: Append domain in domain list
set_fact:
domains: "{{ domains + [item['domain']] }}"
delegate_to: localhost
loop: "{{ froxlor_domains['json']['data']['list'] }}"
when:
- use_froxlor is defined
- use_froxlor == True
- item["documentroot"] != "/var/www/html/"
tags:
- froxlor
- include_tasks: froxlor_configure_vhost.yml
loop: "{{ domains }}"
loop_control:
loop_var: loop_domain
tags:
- froxlor
when:
- use_froxlor is defined
- use_froxlor
- not loop_domain in know_froxlor_domain
- include_tasks: froxlor_delete_vhost.yml
loop: "{{ know_froxlor_domain }}"
loop_control:
loop_var: loop_domain
tags:
- froxlor
when:
- use_froxlor is defined
- use_froxlor
- loop_domain not in domains
- name: Copy using inline content
ansible.builtin.copy:
content: "{{ domains }}"
dest: /etc/nginx/froxlor_domain.json
when:
- use_froxlor is defined
- use_froxlor == True
tags:
- froxlor
notify:
- Reload Nginx