Browse Source

various bug and typos fixes

nginx-letsencrypt
Lorenzo 8 years ago
parent
commit
530c1b2ebb
4 changed files with 23 additions and 15 deletions
  1. +5
    -0
      roles/nginx/defaults/main.yml
  2. +11
    -9
      roles/nginx/tasks/letsencrypt.yaml
  3. +4
    -3
      roles/nginx/tasks/main.yaml
  4. +3
    -3
      roles/nginx/tasks/store_challenge.yaml

+ 5
- 0
roles/nginx/defaults/main.yml View File

@ -19,6 +19,11 @@ nginx_separate_logs_per_site: False
letsencrypt_account_key: "/etc/ssl/private/letsencrypt.key.pem"
letsencrypt_challenge_webroot: "/var/www/html"
letsencrypt_ssl_country: "IT"
letsencrypt_ssl_state: "Italy"
letsencrypt_ssl_loc: "Florence"
letsencrypt_ssl_org: "LILiK"
letsencrypt_ssl_email: "letsencrypt@example.com"
nginx_sites:

+ 11
- 9
roles/nginx/tasks/letsencrypt.yaml View File

@ -3,23 +3,24 @@
path: "{{ item.server.ssl_certificate_key }}"
- name: generate certificate signing request
command: >
command: >
openssl req
-new
-sha256
-nodes
-key {{ item.server.ssl_certificate_key }}
-out {{ item.letsencrypt.ssl_csr }}
-subj "/C={{ item.letsencrypt.ssl_country }}
/ST={{ item.letsencrypt.ssl_state }}
/L{{ item.letsencrypt.ssl_loc }}
/O={{ item.letsencrypt.ssl_org }}
/emailAddress={{ item.letsencrypt.ssl_email }}"
-out {{ item.letsencrypt.ssl_csr | default(item.server.ssl_certificate~".csr") }}
-subj "/C={{ item.letsencrypt.ssl_country | default(letsencrypt_ssl_country)
}}/ST={{ item.letsencrypt.ssl_state | default(letsencrypt_ssl_state)
}}/L{{ item.letsencrypt.ssl_loc | default(letsencrypt_ssl_loc)
}}/O={{ item.letsencrypt.ssl_org | default(letsencrypt_ssl_org)
}}/CN={{ item.letsencrypt.ssl_cn | default(item.server.server_name)
}}/emailAddress={{ item.letsencrypt.ssl_email | default(letsencrypt_ssl_email) }}"
- name: get challenge(s) from letsencrypt server
letsencrypt:
account_key: "{{ letsencrypt_account_key }}"
csr: "{{ item.letsencrypt.ssl_csr }}"
csr: "{{ item.letsencrypt.ssl_csr | default(item.server.ssl_certificate~'.csr') }}"
dest: "{{ item.server.ssl_certificate }}"
register: letsencrypt_challenge
@ -30,6 +31,7 @@
- name: get signed certificate(s) from letsencrypt server
letsencrypt:
account_key: "{{ letsencrypt_account_key }}"
csr: "{{ item.letsencrypt.ssl_csr }}"
csr: "{{ item.letsencrypt.ssl_csr | default(item.server.ssl_certificate~'.csr') }}"
dest: "{{ item.server.ssl_certificate }}"
data: "{{ letsencrypt_challenge }}"
notify: restart nginx

+ 4
- 3
roles/nginx/tasks/main.yaml View File

@ -28,7 +28,7 @@
- name: provision letsencrypt challenge folder
file:
path: "{{ letsencrypt.challenge_webroot }}/.well-known/acme-challenge"
path: "{{ letsencrypt_challenge_webroot }}/.well-known/acme-challenge"
state: directory
owner: root
group: root
@ -82,12 +82,13 @@
dest: "/etc/nginx/sites-available/{{ item.server.file_name }}"
with_items: "{{ nginx_sites }}"
when: nginx_sites is defined and nginx_sites
notify: restart nginx
- name: enable nginx configurations used for letsencrypt challenge
file:
path: "/etc/nginx/sites-enabled/{{ item.server.file_name }}"
state: link
src: "/etc/nginx/sites-enabled/{{ item.server.file_name }}"
src: "/etc/nginx/sites-available/{{ item.server.file_name }}"
with_items: "{{ nginx_sites }}"
when: letsencrypt|bool and item.use_for_challenge is defined and item.use_for_challenge|bool and nginx_sites is defined and nginx_sites
@ -103,7 +104,7 @@
when: letsencrypt|bool
- name: provision ssl cert/key(s) with letsencrypt
include: letsencrypt.yml
include: letsencrypt.yaml
with_items: "{{ nginx_sites }}"
when: letsencrypt|bool and item.letsencrypt is defined and nginx_sites is defined and nginx_sites


+ 3
- 3
roles/nginx/tasks/store_challenge.yaml View File

@ -1,9 +1,9 @@
- name: copy challenge file inside webroot
copy:
dest: "{{ letsencrypt_challenge_webroot }}/{{ chall.value.http-01.resource }}"
content: "{{ chall.value.http-01.resource_value }}"
dest: "{{ letsencrypt_challenge_webroot }}/{{ chall.value['http-01']['resource'] }}"
content: "{{ chall.value['http-01']['resource_value'] }}"
with_dict: "{{ letsencrypt_challenge.challenge_data }}"
loop_contro:
loop_control:
loop_var: chall

Loading…
Cancel
Save