Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use requests lib #940

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions roles/letsencrypt/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@ letsencrypt_min_renewal_age: 60
# good value. It does not harm to run it often, as it will only regenerate certificates that have passed a certain age
# (60 days by default).
letsencrypt_cronjob_daysofmonth: 1,11,21


pip_install_pip: true
pip_version_pip: latest

pip_install_requests: true
pip_version_requests: latest
11 changes: 4 additions & 7 deletions roles/letsencrypt/library/test_challenges.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

import socket
from httplib import HTTPConnection, HTTPException
import requests

DOCUMENTATION = '''
---
Expand Down Expand Up @@ -42,13 +41,11 @@

def get_status(host, path, file):
try:
conn = HTTPConnection(host)
conn.request('HEAD', '/{0}/{1}'.format(path, file))
res = conn.getresponse()
except (HTTPException, socket.timeout, socket.error):
res = requests.head('http://{0}/{1}/{2}'.format(host, path, file))
except requests.RequestException:
return 0
else:
return res.status
return res.status_code

def main():
module = AnsibleModule(
Expand Down
14 changes: 14 additions & 0 deletions roles/letsencrypt/tasks/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,17 @@
url: "{{ letsencrypt_intermediate_cert_url }}"
dest: "{{ letsencrypt_intermediate_cert_path }}"
sha256sum: "{{ letsencrypt_intermediate_cert_sha256sum }}"

- name: Install pip, request
pip:
name: "{{ item.name }}"
state: "{{ 'latest' if item.version=='latest' else 'present' }}"
version: "{{ item.version if item.version!='latest' else omit }}"
with_items:
- name: pip
version: "{{ pip_version_pip }}"
install: "{{ pip_install_pip }}"
- name: requests
version: "{{ pip_version_requests }}"
install: "{{ pip_install_requests }}"
when: item.install|bool