diff --git a/README.md b/README.md index 17bff9d..9bd334e 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Features: - Preconfigured vhost templates (should work on many app) - Auto-configure HTTP2 on SSL/TLS vhosts - Manage dynamic modules (install and loading) +- Deploy custom facts.d with sites config Requirements ------------ diff --git a/tasks/prepare.yml b/tasks/prepare.yml index c3b4fd6..b5b7869 100644 --- a/tasks/prepare.yml +++ b/tasks/prepare.yml @@ -22,3 +22,5 @@ file: dest="{{ item.dir }}" owner="{{ item.owner }}" mode="{{ item.mode }}" state=directory with_items: "{{ nginx_dirs }}" +- name: FILE | Create ansible facts dir + file: path=/etc/ansible/facts.d state=directory diff --git a/tasks/vhost.yml b/tasks/vhost.yml index 933391e..30c0671 100644 --- a/tasks/vhost.yml +++ b/tasks/vhost.yml @@ -61,7 +61,7 @@ file: path={{ nginx_etc_dir}}/sites-enabled/{{ item.filename | default(item.name if item.name is string else item.name[0]) }} state=absent with_items: "{{ nginx_vhosts }}" notify: ['reload nginx', 'restart nginx freebsd'] - when: item.state is defined and item.state == 'disabled' + when: item.state is defined and item.state == 'disabled' - name: FILE | Delete default vhost when explicitely defined file: > @@ -77,3 +77,14 @@ state=link notify: ['reload nginx', 'restart nginx freebsd'] when: nginx_default_vhost is none + +- name: TEMPLATE | Deploy facts + template: + src=etc/ansible/facts.d/nginx.fact.j2 + dest=/etc/ansible/facts.d/nginx.fact + mode=0644 + register: fact + +- name: SETUP + action: setup + when: fact.changed diff --git a/templates/etc/ansible/facts.d/nginx.fact.j2 b/templates/etc/ansible/facts.d/nginx.fact.j2 new file mode 100644 index 0000000..54f202e --- /dev/null +++ b/templates/etc/ansible/facts.d/nginx.fact.j2 @@ -0,0 +1,4 @@ +{ + "fact_nginx_vhosts": + {{ nginx_vhosts | to_nice_json(indent=8) }} +} diff --git a/tests/test.yml b/tests/test.yml index fb0365f..a591bd6 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -235,6 +235,12 @@ - name: -- Add HTML file hello -- copy: dest="{{ nginx_root }}/test-htpasswd.local/public/hello/index.html" content="hello\n" # -------------------------------- +# Test custom facts +# -------------------------------- + - name: -- CHECK FACTS -- + assert: + that: "'{{ ansible_local.nginx.fact_nginx_vhosts[0].name[0] }}' == 'test.local'" +# -------------------------------- # Simple vhosts tests # -------------------------------- - name: -- VERIFY VHOSTS --