瀏覽代碼

Newebe: improve playbook and don't fail on first installation

- Add test
- Fixed Newebe's playbook failing on first run on a fresh Debian 7 VM
- Restart supervisord on changes
- Security: Use /usr/sbin/nologin as login shell for newebe user
- Speed: Consolidate all 'apt' entries into one
- Strip trailing whitespaces
- Update to take advantage of apache2_module from Ansible 1.6
- Use file path=... state=absent instead of "rm" command to delete files
Lorenzo Villani 10 年之前
父節點
當前提交
f3f17a6406
共有 3 個檔案被更改,包括 54 行新增41 行删除
  1. 3
    0
      roles/newebe/handlers/main.yml
  2. 35
    41
      roles/newebe/tasks/main.yml
  3. 16
    0
      tests.py

+ 3
- 0
roles/newebe/handlers/main.yml 查看文件

@@ -0,0 +1,3 @@
1
+---
2
+- name: restart supervisor
3
+  service: name=supervisor state=restarted

+ 35
- 41
roles/newebe/tasks/main.yml 查看文件

@@ -1,20 +1,19 @@
1
-- name: Install Python
2
-  apt: pkg=python,python-setuptools,python-pip,python-dev
3
-
4
-- name: Install Python tools
5
-  apt: pkg=python-imaging,python-pycurl
6
-
7
-- name: Install build tools
8
-  apt: pkg=build-essential,git
9
-
10
-- name: Install Python libs
11
-  apt: pkg=libxml2-dev,libxslt-dev,python-imaging
12
-
13
-- name: Install Supervisor
14
-  apt: pkg=supervisor
15
-
16
-- name: Install CouchDB
17
-  apt: pkg=couchdb
1
+- name: Install Dependencies
2
+  apt: pkg={{ item }}
3
+  with_items:
4
+    - build-essential
5
+    - couchdb
6
+    - git
7
+    - libxml2-dev
8
+    - libxslt-dev
9
+    - python
10
+    - python-dev
11
+    - python-imaging
12
+    - python-imaging
13
+    - python-pip
14
+    - python-pycurl
15
+    - python-setuptools
16
+    - supervisor
18 17
 
19 18
 - name: Install Newebe
20 19
   pip: name='git+https://github.com/gelnior/newebe.git#egg=newebe'
@@ -23,30 +22,30 @@
23 22
   group: name=newebe
24 23
 
25 24
 - name: Add user Newebe
26
-  user: name=newebe shell=/bin/bash groups=newebe
25
+  user: name=newebe groups=newebe shell=/usr/sbin/nologin
27 26
 
28 27
 - name: Create Newebe Config folder
29
-  file: path=/usr/local/etc/newebe/ 
30
-        owner=newebe 
31
-        group=newebe 
28
+  file: path=/usr/local/etc/newebe/
29
+        owner=newebe
30
+        group=newebe
32 31
         state=directory
33 32
 
34 33
 - name: Create Newebe folder
35
-  file: path=/usr/local/var/newebe/ 
36
-        owner=newebe 
37
-        group=newebe 
34
+  file: path=/usr/local/var/newebe/
35
+        owner=newebe
36
+        group=newebe
38 37
         state=directory
39 38
 
40 39
 - name: Create Newebe log folder
41
-  file: path=/usr/local/var/log/newebe/ 
42
-        owner=newebe 
43
-        group=newebe 
40
+  file: path=/usr/local/var/log/newebe/
41
+        owner=newebe
42
+        group=newebe
44 43
         state=directory
45 44
 
46 45
 - name: Set Newebe config file
47 46
   template: src=usr_local_etc_newebe_config.j2
48
-            dest=/usr/local/etc/newebe/config.yaml 
49
-            owner=newebe 
47
+            dest=/usr/local/etc/newebe/config.yaml
48
+            owner=newebe
50 49
             group=newebe
51 50
 
52 51
 - name: Set Supervisor config file
@@ -54,29 +53,25 @@
54 53
 
55 54
 - name: Set Newebe Supervisor config file
56 55
   copy: src=supervisor.conf dest=/etc/supervisor/supervisor.conf
56
+  notify: restart supervisor
57 57
 
58
-- name: Reload Supervisor and start Newebe
59
-  command: /usr/bin/supervisorctl update
58
+- name: Ensure Supervisor is running
59
+  service: name=supervisor state=running
60 60
 
61 61
 - name: Ensure that newebe is started
62 62
   supervisorctl: name=newebe state=started
63 63
 
64 64
 - name: Add mod_proxy module to Apache
65
-  raw: a2enmod proxy
66
-# When Ansible 1.6 will be available  
67
-# apache2_module: state=present name=proxy
65
+  apache2_module: state=present name=proxy
68 66
 
69 67
 - name: Add proxy_http module to Apache
70
-  raw: a2enmod proxy_http
71
-# When Ansible 1.6 will be available  
72
-# apache2_module: state=present name=proxy_http
73
-#
68
+  apache2_module: state=present name=proxy_http
74 69
 
75 70
 - name: Rename existing Apache newebe virtualhost
76 71
   command: mv /etc/apache2/sites-available/newebe /etc/apache2/sites-available/newebe.conf removes=/etc/apache2/sites-available/newebe
77 72
 
78 73
 - name: Remove old sites-enabled/newebe symlink (new one will be created by a2ensite)
79
-  command: rm /etc/apache2/sites-enabled/newebe removes=/etc/apache2/sites-enabled/newebe
74
+  file: path=/etc/apache2/sites-enabled/newebe state=absent
80 75
 
81 76
 - name: Configure the Apache HTTP server for Newebe
82 77
   template: src=etc_apache2_sites-available_newebe.j2
@@ -85,6 +80,5 @@
85 80
             owner=root
86 81
 
87 82
 - name: Enable the site
88
-  command: a2ensite newebe.conf
89
-           creates=/etc/apache2/sites-enabled/newebe.conf
83
+  command: a2ensite newebe.conf creates=/etc/apache2/sites-enabled/newebe.conf
90 84
   notify: restart apache

+ 16
- 0
tests.py 查看文件

@@ -127,6 +127,22 @@ class WebTests(unittest.TestCase):
127 127
             r.content
128 128
         )
129 129
 
130
+    def test_newebe_http(self):
131
+        """Newebe is displaying home page"""
132
+        r = requests.get('http://newebe.' + TEST_SERVER, verify=False)
133
+
134
+        # We should be redirected to https
135
+        self.assertEquals(r.history[0].status_code, 301)
136
+        self.assertEquals(r.url, 'https://newebe.' + TEST_SERVER + '/')
137
+
138
+        # 200 - We should be at the repository page
139
+        self.assertEquals(r.status_code, 200)
140
+        self.assertIn(
141
+            'Newebe, Freedom to Share',
142
+            r.content
143
+        )
144
+
145
+
130 146
 class IRCTests(unittest.TestCase):
131 147
     def test_irc_auth(self):
132 148
         """ZNC is accepting encrypted logins"""

Loading…
取消
儲存