2017-12-03 04:22:28 +07:00
|
|
|
---
|
|
|
|
|
|
|
|
- name: SET_FACT | Assign default..
|
|
|
|
set_fact:
|
|
|
|
acme_create: []
|
|
|
|
|
|
|
|
- name: STAT | Check if certificates are already installed
|
|
|
|
stat:
|
|
|
|
path: "{{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.crt"
|
2019-02-05 03:25:25 +07:00
|
|
|
loop: "{{ nginx_ssl_pairs }}"
|
2017-12-03 04:22:28 +07:00
|
|
|
when: item.acme is defined and item.acme
|
|
|
|
register: acme_installed_certs
|
|
|
|
|
|
|
|
- name: SET_FACT | Assign var with certificates to create
|
|
|
|
set_fact:
|
2018-03-23 02:35:51 +07:00
|
|
|
acme_create: "{{ acme_create | default([]) + [ (item.item) ] }}"
|
2019-02-05 03:25:25 +07:00
|
|
|
loop: "{{ acme_installed_certs.results }}"
|
2017-12-03 04:22:28 +07:00
|
|
|
when: item.skipped is not defined and not item.stat.exists
|
|
|
|
|
2019-04-25 18:59:19 +07:00
|
|
|
- name: BLOCK | Start acme
|
|
|
|
block:
|
|
|
|
|
|
|
|
- name: TEMPLATE | Create fake site
|
|
|
|
template:
|
|
|
|
src: "etc/nginx/conf.d/FAKESITE.conf.j2"
|
|
|
|
dest: "{{ nginx_etc_dir }}/conf.d/FAKESITE_{{ item | nginx_site_name }}.conf"
|
|
|
|
loop: "{{ acme_create }}"
|
|
|
|
register: fake_site
|
|
|
|
|
|
|
|
- name: FILE | Delete current site if needed
|
|
|
|
file:
|
|
|
|
path: "{{ nginx_etc_dir }}/sites-enabled/{{ item | nginx_site_name }}"
|
|
|
|
state: absent
|
|
|
|
loop: "{{ acme_create }}"
|
|
|
|
when: fake_site.changed
|
|
|
|
|
|
|
|
- name: SERVICE | Restart nginx
|
|
|
|
service:
|
|
|
|
name: nginx
|
|
|
|
state: restarted
|
|
|
|
when: fake_site.changed and ansible_virtualization_type != 'docker'
|
|
|
|
|
|
|
|
- name: COMMAND | Restart nginx
|
|
|
|
command: service nginx restart
|
|
|
|
args:
|
|
|
|
warn: false
|
|
|
|
when: fake_site.changed and ansible_virtualization_type == 'docker'
|
|
|
|
|
2019-04-26 18:29:06 +07:00
|
|
|
- name: COMMAND | Get certificates
|
|
|
|
command: |
|
|
|
|
{{ nginx_acmesh_bin }}
|
|
|
|
--home {{ nginx_acmesh_dir }}
|
|
|
|
--issue{% if item.name is string %} -d {{ item.name }}{% else %}{% for name in item.name %} -d {{ name }}{% endfor %}{% endif %}
|
|
|
|
--nginx
|
|
|
|
{% if nginx_acmesh_test %}--test{% endif %}
|
2019-04-25 18:59:19 +07:00
|
|
|
args:
|
|
|
|
creates: "{{ nginx_acmesh_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.key"
|
|
|
|
loop: "{{ acme_create }}"
|
|
|
|
register: acme_get
|
|
|
|
failed_when: acme_get.rc != 0 and acme_get.rc != 2
|
|
|
|
no_log: not nginx_debug_role
|
|
|
|
|
|
|
|
- name: FILE | Create SSL dir per site
|
|
|
|
file:
|
|
|
|
path: "{{ nginx_ssl_dir }}/{{ item | nginx_site_name }}"
|
|
|
|
loop: "{{ acme_create }}"
|
|
|
|
|
2019-04-26 18:29:06 +07:00
|
|
|
- name: COMMAND | Install certificates
|
|
|
|
command: |
|
|
|
|
{{ nginx_acmesh_bin }}
|
|
|
|
--home {{ nginx_acmesh_dir }}
|
|
|
|
--install-cert -d {{ item | nginx_site_name }}
|
|
|
|
--fullchain-file {{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.crt
|
|
|
|
--key-file {{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.key
|
2019-04-30 21:45:14 +07:00
|
|
|
--reloadcmd "service nginx reload"
|
2019-04-25 18:59:19 +07:00
|
|
|
args:
|
|
|
|
creates: "{{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.key"
|
|
|
|
loop: "{{ nginx_ssl_pairs }}"
|
|
|
|
when: item.acme is defined and item.acme
|
|
|
|
notify: restart nginx
|
|
|
|
|
|
|
|
rescue:
|
|
|
|
|
|
|
|
- name: FAIL | Explicit
|
|
|
|
fail:
|
|
|
|
msg: "Something is bad... Auto crash!"
|
|
|
|
|
|
|
|
always:
|
|
|
|
|
|
|
|
- name: FILE | Delete fake sites
|
|
|
|
file:
|
|
|
|
path: "{{ nginx_etc_dir }}/conf.d/FAKESITE_{{ item | nginx_site_name }}.conf"
|
|
|
|
state: absent
|
|
|
|
loop: "{{ acme_create }}"
|
|
|
|
notify: restart nginx
|
2017-12-03 04:22:28 +07:00
|
|
|
|
2019-04-25 18:59:19 +07:00
|
|
|
- name: META | Flush handlers
|
|
|
|
meta: flush_handlers
|