Skip to content

Instantly share code, notes, and snippets.

@ezhulkov
Created January 2, 2019 06:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezhulkov/883897a0f69fb5aeed88cf0543ad4fc5 to your computer and use it in GitHub Desktop.
Save ezhulkov/883897a0f69fb5aeed88cf0543ad4fc5 to your computer and use it in GitHub Desktop.
- name: enabling ssl
block:
- name: certbot dirs
file: path={{item}} state=directory mode=0755 group=root owner=root
with_items:
- "/var/lib/certbot/www"
- "/var/log/certbot"
- "/var/lib/certbot/conf/live/{{server_name}}"
- name: creating dummy certificate
docker_container:
name: 'openssl'
image: 'frapsoft/openssl'
state: 'started'
auto_remove: yes
command: "req -x509 -nodes -newkey rsa:1024 -days 1 \
-keyout '/etc/letsencrypt/live/{{server_name}}/privkey.pem' \
-out '/etc/letsencrypt/live/{{server_name}}/fullchain.pem' \
-subj '/CN=localhost'"
volumes:
- "/var/lib/certbot/conf:/etc/letsencrypt"
- name: copying options-ssl-nginx.conf
copy: src=options-ssl-nginx.conf dest=/var/lib/certbot/conf/options-ssl-nginx.conf owner=root group=root mode=0644
- name: copying ssl-dhparams.pem
copy: src=ssl-dhparams.pem dest=/var/lib/certbot/conf/ssl-dhparams.pem owner=root group=root mode=0644
- name: starting nginx with dummy certificate
docker_container:
name: 'nginx'
state: 'started'
- name: waiting for nginx
wait_for: port=80
- name: deleting dummy certificates
file: path={{item}} state=absent mode=0640 group=root owner=root
with_items:
- "/var/lib/certbot/conf/live/{{server_name}}"
- name: requesting letsencrypt certificate
docker_container:
name: 'certbot'
image: 'certbot/certbot'
state: 'started'
auto_remove: yes
command: "certonly --webroot --webroot-path /var/www/certbot \
--email noc@gopractice.io --cert-name {{server_name}} \
-d {{server_name}} --rsa-key-size 4096 \
--agree-tos --force-renewal"
volumes:
- "/var/lib/certbot/conf:/etc/letsencrypt"
- "/var/lib/certbot/www:/var/www/certbot"
- "/var/log/certbot:/var/log/letsencrypt"
- name: waiting for certbot
wait_for: path=/var/log/certbot/letsencrypt.log search_regex="Your key file has been saved at"
- name: restart nginx with prod certificate
docker_container:
name: 'nginx'
state: 'started'
restart: yes
- name: waiting for nginx
wait_for: port=80
when: docker_nginx_ssl == "true"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment