From ae85b4b3012748aa3de7d5de8e6c8013f9b4178d Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Fri, 24 Feb 2017 09:07:23 +0200
Subject: [PATCH] - Support only OSes that have certbot packaged. - Early stage
 of role, WIP.

---
 .gitmodules           |  3 +++
 .travis.yml           |  3 ---
 defaults/main.yml     |  3 +++
 library/shore         |  1 +
 meta/main.yml         |  8 +++++---
 tasks/main.yml        | 26 +++++++++++++++++++++++++-
 templates/cli.ini     |  3 +++
 tests/test_certbot.py |  2 ++
 8 files changed, 42 insertions(+), 7 deletions(-)
 create mode 100644 .gitmodules
 create mode 160000 library/shore
 create mode 100644 templates/cli.ini

diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..c8bc96e
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "library/shore"]
+	path = library/shore
+	url = https://www.shore.co.il/git/ansible-modules
diff --git a/.travis.yml b/.travis.yml
index 110a35a..95185ad 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -11,11 +11,8 @@ env:
         - platform: openbsd60
         - &openbsd59 platform=openbsd59
         - platform: xenial
-        - platform: trusty
-        - platform: precise
         - &stretch platform=stretch
         - platform: jessie
-        - platform: wheezy
 matrix:
     fast_finish: True
     allow_failures:
diff --git a/defaults/main.yml b/defaults/main.yml
index 2949b39..ac395c9 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -1,2 +1,5 @@
 ---
 # defaults file for certbot
+
+certbot_config:
+    domains: example.com
diff --git a/library/shore b/library/shore
new file mode 160000
index 0000000..2efdc7b
--- /dev/null
+++ b/library/shore
@@ -0,0 +1 @@
+Subproject commit 2efdc7b0a7d963ca5f2d7887530776906b319486
diff --git a/meta/main.yml b/meta/main.yml
index b93e205..2e1dfec 100644
--- a/meta/main.yml
+++ b/meta/main.yml
@@ -12,14 +12,16 @@ galaxy_info:
   - name: Ubuntu
     versions:
     - xenial
-    - trusty
-    - precise
   - name: Debian
     versions:
     - stretch
     - jessie
-    - wheezy
   galaxy_tags: [ ansible ]
 dependencies:
     - name: python27
       src: adarnimrod.python27
+    - name: backports
+      src: adarnimrod.backports
+      when: ansible_os_family == 'Debian' and ansible_distribution_release == 'jessie'
+    - name: ca-store
+      src: adarnimrod.ca-store
diff --git a/tasks/main.yml b/tasks/main.yml
index dc0d7e8..1538460 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -5,4 +5,28 @@
   assert:
     that:
         - ansible_os_family in ['OpenBSD', 'Debian']
-        - ansible_distribution_release in ['6.0', '5.9', 'xenial', 'trusty', 'precise', 'stretch', 'jessie', 'wheezy']
+        - ansible_distribution_release in ['6.0', '5.9', 'xenial', 'trusty', 'precise', 'stretch', 'jessie']
+        - certbot_config is iterable
+        - certbot_config['domains'] is defined
+
+- name: APT install
+  when: ansible_pkg_mgr == 'apt'
+  apt:
+      name: letsencrypt
+      state: present
+      update_cache: yes
+      cache_valid_time: 3600
+
+- name: pkg add
+  when: ansible_pkg_mgr == 'openbsd_pkg'
+  openbsd_pkg:
+      name: letsencrypt
+      state: present
+
+- name: Copy config
+  template:
+      src: cli.ini
+      dest: /etc/letsencrypt/cli.ini
+      owner: root
+      group: 0
+      mode: 0o0644
diff --git a/templates/cli.ini b/templates/cli.ini
new file mode 100644
index 0000000..11b453d
--- /dev/null
+++ b/templates/cli.ini
@@ -0,0 +1,3 @@
+{% for key, value in certbot_config.iteritems() -%}
+{{ key }} = {{ value }}
+{%- endfor %}
diff --git a/tests/test_certbot.py b/tests/test_certbot.py
index e69de29..9fb7fb9 100644
--- a/tests/test_certbot.py
+++ b/tests/test_certbot.py
@@ -0,0 +1,2 @@
+def test_certbot_cli(Command):
+    assert Command('letsencrypt --version').rc == 0
-- 
GitLab