subspace 0.1.1 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -0
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +1 -1
  5. data/CHANGELOG.md +380 -0
  6. data/README.md +511 -9
  7. data/TODO +34 -0
  8. data/UPGRADING.md +10 -0
  9. data/ansible/playbooks/local_template.yml +13 -0
  10. data/ansible/playbooks/maintenance_mode.yml +5 -0
  11. data/ansible/roles/alienvault/tasks/main.yml +29 -0
  12. data/ansible/roles/apache/defaults/main.yml +2 -5
  13. data/ansible/roles/apache/handlers/main.yml +9 -1
  14. data/ansible/roles/apache/tasks/main.yml +37 -9
  15. data/ansible/roles/apache/templates/server_status.conf +6 -0
  16. data/ansible/roles/apache-rails/tasks/main.yml +26 -0
  17. data/ansible/roles/apache-rails/templates/_canonical_domain.conf +10 -0
  18. data/ansible/roles/apache-rails/templates/_rails.conf +23 -0
  19. data/ansible/roles/apache-rails/templates/project-ssl.conf +23 -0
  20. data/ansible/roles/apache-rails/templates/project.conf +5 -0
  21. data/ansible/roles/collectd/defaults/main.yml +3 -0
  22. data/ansible/roles/collectd/handlers/main.yml +3 -0
  23. data/ansible/roles/collectd/tasks/main.yml +82 -0
  24. data/ansible/roles/collectd/templates/apache2.conf +6 -0
  25. data/ansible/roles/collectd/templates/delayed_job_postgres.conf +21 -0
  26. data/ansible/roles/collectd/templates/df.conf +16 -0
  27. data/ansible/roles/collectd/templates/graphite.conf +14 -0
  28. data/ansible/roles/collectd/templates/hostname.conf +2 -0
  29. data/ansible/roles/collectd/templates/nginx.conf +28 -0
  30. data/ansible/roles/collectd/templates/nodejs-process.conf +3 -0
  31. data/ansible/roles/collectd/templates/puma-process.conf +3 -0
  32. data/ansible/roles/collectd/templates/rails_lograge.conf +31 -0
  33. data/ansible/roles/common/defaults/main.yml +2 -1
  34. data/ansible/roles/common/files/sudoers-service +1 -0
  35. data/ansible/roles/common/tasks/main.yml +307 -19
  36. data/ansible/roles/common/tasks/no_swap.yml +26 -0
  37. data/ansible/roles/common/tasks/swap.yml +34 -8
  38. data/ansible/roles/common/templates/motd +13 -0
  39. data/ansible/roles/common/templates/motd2 +24 -0
  40. data/ansible/roles/common/templates/terminalcolor +25 -0
  41. data/ansible/roles/delayed_job/README.md +2 -4
  42. data/ansible/roles/delayed_job/defaults/main.yml +0 -2
  43. data/ansible/roles/delayed_job/handlers/main.yml +1 -1
  44. data/ansible/roles/delayed_job/tasks/main.yml +22 -29
  45. data/ansible/roles/delayed_job/templates/delayed-job-monit-rc +6 -5
  46. data/ansible/roles/delayed_job/templates/delayed-job-systemd.service +33 -0
  47. data/ansible/roles/gem-patch-report/README.md +137 -0
  48. data/ansible/roles/gem-patch-report/defaults/main.yml +2 -0
  49. data/ansible/roles/gem-patch-report/tasks/main.yml +89 -0
  50. data/ansible/roles/gem-patch-report/templates/gem-patch-report.sh.j2 +114 -0
  51. data/ansible/roles/letsencrypt/defaults/main.yml +11 -1
  52. data/ansible/roles/letsencrypt/tasks/legacy.yml +44 -0
  53. data/ansible/roles/letsencrypt/tasks/main.yml +72 -76
  54. data/ansible/roles/letsencrypt/tasks/modern.yml +39 -0
  55. data/ansible/roles/logrotate/LICENSE +27 -0
  56. data/ansible/roles/logrotate/README.md +70 -0
  57. data/ansible/roles/logrotate/defaults/main.yml +2 -0
  58. data/ansible/roles/logrotate/meta/main.yml +18 -0
  59. data/ansible/roles/logrotate/tasks/main.yml +15 -0
  60. data/ansible/roles/logrotate/templates/logrotate.d.j2 +16 -0
  61. data/ansible/roles/memcache/defaults/main.yml +2 -0
  62. data/ansible/roles/memcache/tasks/main.yml +16 -1
  63. data/ansible/roles/mysql/meta/main.yml +1 -1
  64. data/ansible/roles/mysql/tasks/main.yml +2 -2
  65. data/ansible/roles/mysql2_gem/meta/main.yml +1 -1
  66. data/ansible/roles/mysql2_gem/tasks/main.yml +1 -1
  67. data/ansible/roles/newrelic/tasks/main.yml +8 -1
  68. data/ansible/roles/newrelic-infra/defaults/main.yml +2 -0
  69. data/ansible/roles/newrelic-infra/handlers/main.yml +5 -0
  70. data/ansible/roles/newrelic-infra/tasks/main.yml +38 -0
  71. data/ansible/roles/newrelic-infra/templates/logs.yml.j2 +5 -0
  72. data/ansible/roles/newrelic-infra/templates/newrelic-infra.yml.j2 +2 -0
  73. data/ansible/roles/nginx/defaults/main.yml +4 -0
  74. data/ansible/roles/nginx/handlers/main.yml +12 -0
  75. data/ansible/roles/nginx/tasks/main.yml +113 -14
  76. data/ansible/roles/nginx/templates/nginx.conf +29 -0
  77. data/ansible/roles/nginx/templates/status +10 -0
  78. data/ansible/roles/nginx-maintenance/tasks/main.yml +33 -0
  79. data/ansible/roles/nginx-rails/defaults/main.yml +6 -0
  80. data/ansible/roles/nginx-rails/tasks/main.yml +54 -0
  81. data/ansible/roles/nginx-rails/templates/_asset_cors.conf +11 -0
  82. data/ansible/roles/nginx-rails/templates/_rails.conf +35 -0
  83. data/ansible/roles/nginx-rails/templates/_upstream.conf +11 -0
  84. data/ansible/roles/nginx-rails/templates/default_server +5 -0
  85. data/ansible/roles/nginx-rails/templates/nginx-project +9 -0
  86. data/ansible/roles/nginx-rails/templates/nginx-project-ssl +23 -0
  87. data/ansible/roles/nodejs/tasks/main.yml +33 -0
  88. data/ansible/roles/papertrail/tasks/main.yml +23 -4
  89. data/ansible/roles/papertrail/templates/log_files.yml +8 -1
  90. data/ansible/roles/postgis/.gitignore +3 -0
  91. data/ansible/roles/postgis/CHANGELOG.md +24 -0
  92. data/ansible/roles/postgis/LICENSE +202 -0
  93. data/ansible/roles/postgis/README.md +12 -0
  94. data/ansible/roles/postgis/meta/main.yml +15 -0
  95. data/ansible/roles/postgis/tasks/main.yml +20 -0
  96. data/ansible/roles/postgresql/README.md +15 -0
  97. data/ansible/roles/postgresql/defaults/main.yml +3 -0
  98. data/ansible/roles/postgresql/handlers/main.yml +1 -1
  99. data/ansible/roles/postgresql/meta/main.yml +1 -6
  100. data/ansible/roles/postgresql/tasks/backups.yml +8 -6
  101. data/ansible/roles/postgresql/tasks/main.yml +89 -9
  102. data/ansible/roles/postgresql/templates/backup.sh +17 -2
  103. data/ansible/roles/postgresql-client/tasks/main.yml +91 -0
  104. data/ansible/roles/puma/tasks/main.yml +38 -19
  105. data/ansible/roles/puma/templates/puma-monit-rc +5 -0
  106. data/ansible/roles/puma/templates/puma-systemd.service +43 -0
  107. data/ansible/roles/puma/templates/puma-systemd.socket +14 -0
  108. data/ansible/roles/puma/templates/puma.rb +24 -12
  109. data/ansible/roles/rails/defaults/main.yml +1 -3
  110. data/ansible/roles/rails/tasks/main.yml +76 -18
  111. data/ansible/roles/rails/templates/application.yml +1 -1
  112. data/ansible/roles/rails/templates/database.yml +3 -3
  113. data/ansible/roles/redis/defaults/main.yml +2 -0
  114. data/ansible/roles/redis/tasks/main.yml +45 -3
  115. data/ansible/roles/resque/tasks/main.yml +14 -0
  116. data/ansible/roles/resque/templates/resque-monit-rc +4 -0
  117. data/ansible/roles/resque/templates/resque-systemd.service +54 -0
  118. data/ansible/roles/ruby-common/README.md +1 -1
  119. data/ansible/roles/ruby-common/defaults/main.yml +1 -0
  120. data/ansible/roles/ruby-common/tasks/main.yml +55 -13
  121. data/ansible/roles/sidekiq/README.md +1 -0
  122. data/ansible/roles/sidekiq/defaults/main.yml +2 -0
  123. data/ansible/roles/sidekiq/tasks/main.yml +15 -0
  124. data/ansible/roles/sidekiq/templates/sidekiq-monit-rc +4 -0
  125. data/ansible/roles/sidekiq/templates/sidekiq-systemd.service +63 -0
  126. data/ansible/roles/tailscale/defaults/main.yml +2 -0
  127. data/ansible/roles/tailscale/tasks/main.yml +40 -0
  128. data/ansible/roles/yarn/tasks/main.yml +19 -0
  129. data/ansible/roles/zenoamaro.postgresql/.gitignore +1 -0
  130. data/ansible/roles/zenoamaro.postgresql/.travis.yml +28 -0
  131. data/ansible/roles/zenoamaro.postgresql/LICENSE.md +21 -0
  132. data/ansible/roles/zenoamaro.postgresql/README.md +117 -0
  133. data/ansible/roles/zenoamaro.postgresql/Vagrantfile +62 -0
  134. data/ansible/roles/zenoamaro.postgresql/boxed.yml +26 -0
  135. data/ansible/roles/zenoamaro.postgresql/defaults/main.yml +607 -0
  136. data/ansible/roles/zenoamaro.postgresql/handlers/main.yml +8 -0
  137. data/ansible/roles/zenoamaro.postgresql/inventory +19 -0
  138. data/ansible/roles/zenoamaro.postgresql/main.yml +19 -0
  139. data/ansible/roles/zenoamaro.postgresql/meta/.galaxy_install_info +1 -0
  140. data/ansible/roles/zenoamaro.postgresql/meta/main.yml +21 -0
  141. data/ansible/roles/zenoamaro.postgresql/tasks/configure.yml +55 -0
  142. data/ansible/roles/zenoamaro.postgresql/tasks/extensions.yml +49 -0
  143. data/ansible/roles/zenoamaro.postgresql/tasks/install.yml +51 -0
  144. data/ansible/roles/zenoamaro.postgresql/tasks/main.yml +5 -0
  145. data/ansible/roles/zenoamaro.postgresql/templates/environment +11 -0
  146. data/ansible/roles/zenoamaro.postgresql/templates/pg_ctl.conf +5 -0
  147. data/ansible/roles/zenoamaro.postgresql/templates/pg_hba.conf +112 -0
  148. data/ansible/roles/zenoamaro.postgresql/templates/pg_ident.conf +46 -0
  149. data/ansible/roles/zenoamaro.postgresql/templates/postgresql.conf +536 -0
  150. data/ansible/roles/zenoamaro.postgresql/test.yml +24 -0
  151. data/bin/console +0 -4
  152. data/exe/subspace +3 -84
  153. data/lib/subspace/cli.rb +168 -0
  154. data/lib/subspace/commands/ansible.rb +35 -0
  155. data/lib/subspace/commands/base.rb +94 -0
  156. data/lib/subspace/commands/bootstrap.rb +49 -0
  157. data/lib/subspace/commands/configure.rb +27 -0
  158. data/lib/subspace/commands/exec.rb +20 -0
  159. data/lib/subspace/commands/init.rb +144 -0
  160. data/lib/subspace/commands/inventory.rb +54 -0
  161. data/lib/subspace/commands/maintain.rb +16 -0
  162. data/lib/subspace/commands/maintenance_mode.rb +16 -0
  163. data/lib/subspace/commands/override.rb +21 -0
  164. data/lib/subspace/commands/provision.rb +14 -0
  165. data/lib/subspace/commands/secrets.rb +69 -0
  166. data/lib/subspace/commands/ssh.rb +33 -0
  167. data/lib/subspace/commands/terraform.rb +89 -0
  168. data/lib/subspace/configuration.rb +71 -0
  169. data/lib/subspace/inventory.rb +144 -0
  170. data/lib/subspace/version.rb +1 -1
  171. data/lib/subspace.rb +8 -1
  172. data/subspace.gemspec +14 -3
  173. data/template/provision.rb.erb +94 -0
  174. data/template/subspace/.gitignore +6 -0
  175. data/template/subspace/ansible.cfg.erb +17 -0
  176. data/template/subspace/group_vars/all.erb +28 -0
  177. data/template/subspace/group_vars/template.erb +26 -0
  178. data/template/subspace/inventory.yml.erb +12 -0
  179. data/template/subspace/playbook.yml.erb +18 -0
  180. data/template/subspace/secrets/template.erb +5 -0
  181. data/template/subspace/templates/application.yml.template +27 -0
  182. data/template/subspace/templates/authorized_keys.erb +1 -0
  183. data/template/subspace/terraform/.gitignore +2 -0
  184. data/template/subspace/terraform/template/main-oxenwagen.tf.erb +116 -0
  185. data/template/subspace/terraform/template/main-workhorse.tf.erb +41 -0
  186. data/template/subspace/terraformrc.erb +9 -0
  187. data/terraform/modules/s3_backend/README +2 -0
  188. data/terraform/modules/s3_backend/dynamodb.tf +1 -0
  189. data/terraform/modules/s3_backend/iam_user.tf +38 -0
  190. data/terraform/modules/s3_backend/main.tf +39 -0
  191. data/terraform/modules/s3_backend/state_bucket.tf +14 -0
  192. metadata +198 -29
  193. data/ansible/roles/apache/templates/project.conf +0 -25
  194. data/ansible/roles/aws/tasks/main.yml +0 -46
  195. data/ansible/roles/delayed_job/files/deploy-service +0 -2
  196. data/ansible/roles/delayed_job/files/monit-http.conf +0 -3
  197. data/ansible/roles/letsencrypt/templates/project-le-ssl.conf +0 -31
  198. data/ansible/roles/nginx/templates/nginx-project +0 -27
  199. data/ansible/roles/puma/templates/etc-init-puma-manager.conf +0 -31
  200. data/ansible/roles/puma/templates/etc-init-puma.conf +0 -69
  201. data/lib/subspace/railtie.rb +0 -9
  202. data/lib/tasks/provision.rake +0 -12
  203. data/template/provision/.gitignore +0 -1
  204. data/template/provision/ansible.cfg.erb +0 -5
  205. data/template/provision/group_vars/all.erb +0 -12
  206. data/template/provision/group_vars/template.erb +0 -14
  207. data/template/provision/host_vars/template.erb +0 -4
  208. data/template/provision/playbook.yml.erb +0 -26
  209. data/template/provision/vars/template.erb +0 -4
  210. /data/template/{provision → subspace}/hosts.erb +0 -0
@@ -0,0 +1,33 @@
1
+ ---
2
+ - name: Add NodeSource repositories for Node.js.
3
+ ansible.builtin.deb822_repository:
4
+ name: node_repo
5
+ types: [deb]
6
+ uris: "https://deb.nodesource.com/node_{{ nodejs_version }}/"
7
+ components: [main]
8
+ suites: [nodistro]
9
+ signed_by: https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key
10
+ state: present
11
+ enabled: true
12
+
13
+ # - name: Add Nodesource apt key.
14
+ # apt_key:
15
+ # url: https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key
16
+ # id: "9B1BE0B4"
17
+ # state: present
18
+
19
+ # - name: Add NodeSource repositories for Node.js.
20
+ # apt_repository:
21
+ # repo: "{{ item }}"
22
+ # state: present
23
+ # with_items:
24
+ # - "deb https://deb.nodesource.com/node_{{ nodejs_version }} nodistro main"
25
+ # - "deb-src https://deb.nodesource.com/node_{{ nodejs_version }} nodistro main"
26
+ # register: node_repo
27
+
28
+
29
+ - name: Ensure Node.js and npm are installed.
30
+ apt:
31
+ update_cache: yes
32
+ name: nodejs={{ nodejs_version|regex_replace('x', '') }}*
33
+ state: present
@@ -1,12 +1,31 @@
1
1
  ---
2
2
  - name: Install remote_syslog from papertrail
3
- command: wget -O /tmp/remote_syslog.tar.gz https://github.com/papertrail/remote_syslog2/releases/download/v0.13/remote_syslog_linux_amd64.tar.gz creates=/usr/bin/remote_syslog
3
+ command: wget -O /tmp/remote_syslog.tar.gz https://github.com/papertrail/remote_syslog2/releases/download/v0.20/remote_syslog_linux_amd64.tar.gz creates=/usr/bin/remote_syslog
4
+
4
5
  - command: tar xzf /tmp/remote_syslog.tar.gz chdir=/tmp/ creates=/usr/bin/remote_syslog
6
+
5
7
  - command: mv /tmp/remote_syslog/remote_syslog /usr/bin/remote_syslog creates=/usr/bin/remote_syslog
8
+ become: true
9
+
6
10
  - file: path=/usr/bin/remote_syslog owner=root group=root mode=0755
7
- - command: wget -O /etc/init.d/remote_syslog https://raw.githubusercontent.com/papertrail/remote_syslog2/v0.13/examples/remote_syslog.init.d creates=/etc/init.d/remote_syslog
11
+ become: true
12
+
13
+ - command: wget -O /etc/init.d/remote_syslog https://raw.githubusercontent.com/papertrail/remote_syslog2/v0.20/examples/remote_syslog.init.d creates=/etc/init.d/remote_syslog
14
+ become: true
15
+
8
16
  - file: path=/etc/init.d/remote_syslog owner=root group=root mode=0755
17
+ become: true
18
+
9
19
  - file: path=/tmp/remote_syslog/ state=absent
20
+
10
21
  - file: path=/tmp/remote_syslog.tar.gz state=absent
11
- - service: name=remote_syslog state=restarted enabled=yes
12
- - template: src=log_files.yml dest=/etc/log_files.yml owner=root group=root mode=0644
22
+
23
+ - name: Create /etc/log_files
24
+ template: src=log_files.yml dest=/etc/log_files.yml owner=root group=root mode=0644
25
+ become: true
26
+
27
+ - name: Restart rsyslog
28
+ service: name=remote_syslog state=restarted enabled=yes
29
+ become: true
30
+
31
+
@@ -1,7 +1,14 @@
1
1
  # Variables: papertrail_host, papertrail_port
2
2
  files:
3
- - /var/log/apache2/error.log
4
3
  - /u/apps/{{project_name}}/shared/log/{{rails_env}}.log
4
+ {% if nginx_installed is defined %}
5
+ - /var/log/nginx/error.log
6
+ {% endif %}
7
+ {% if apache_installed is defined %}
8
+ - /var/log/apache2/error.log
9
+ {% endif %}
10
+
5
11
  destination:
6
12
  host: {{papertrail_host}}
7
13
  port: {{papertrail_port}}
14
+ protocol: tls
@@ -0,0 +1,3 @@
1
+ .vagrant
2
+
3
+ examples/roles/azavea.postgresql
@@ -0,0 +1,24 @@
1
+ ## 0.3.0
2
+
3
+ - Add support for Ansible 2.0.
4
+
5
+ ## 0.2.1
6
+
7
+ - Make use of version blob.
8
+ - Confirm PostgreSQL 9.4 support.
9
+
10
+ ## 0.2.0
11
+
12
+ - Remove explicit PostGIS library geometry library installation.
13
+
14
+ ## 0.1.2
15
+
16
+ - Add variable for passing version and package version of `liblwgeom`.
17
+
18
+ ## 0.1.1
19
+
20
+ - Install the PostGIS lightweight geometry library dependency.
21
+
22
+ ## 0.1.0
23
+
24
+ - Initial release.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,12 @@
1
+ # ansible-postgis
2
+
3
+ An Ansible role for installing [PostGIS](http://postgis.net).
4
+
5
+ ## Role Variables
6
+
7
+ - `postgis_version` - PostGIS version (default: `2.1`)
8
+ - `postgis_package_version` - PostGIS package version (default: `2.1.2+dfsg-2`)
9
+
10
+ ## Example Playbook
11
+
12
+ See the [examples](./examples/) directory.
@@ -0,0 +1,15 @@
1
+ ---
2
+ galaxy_info:
3
+ author: Hector Castro
4
+ description: An Ansible role for installing PostGIS.
5
+ company: Azavea Inc.
6
+ license: Apache
7
+ min_ansible_version: 1.8
8
+ platforms:
9
+ - name: Ubuntu
10
+ versions:
11
+ - trusty
12
+ categories:
13
+ - database:sql
14
+ dependencies:
15
+ - { role: "postgresql" }
@@ -0,0 +1,20 @@
1
+ ---
2
+ - name: Configure the PostgreSQL APT key
3
+ apt_key: url=https://www.postgresql.org/media/keys/ACCC4CF8.asc state=present
4
+
5
+ - name: Configure the PostgreSQL APT repositories
6
+ apt_repository: repo="deb http://apt.postgresql.org/pub/repos/apt/ {{ ansible_facts["distribution_release"]}}-pgdg main"
7
+ state=present
8
+
9
+ - name: Install PostGIS
10
+ apt: pkg={{ item }} state=present
11
+ with_items:
12
+ - postgresql-{{ postgresql_version }}-postgis-{{ postgis_version }}
13
+
14
+ - name: "Enable postgres postgis"
15
+ become: true
16
+ become_user: postgres
17
+ postgresql_ext:
18
+ db: "{{database_name}}"
19
+ name: postgis
20
+ state: present
@@ -0,0 +1,15 @@
1
+ Attach this as a bucket policy to allow unauthenticated writes. Then you can set "s3_db_backup_bucket" to upload backups to your s3 bucket instead of keeping backups on the local machine.
2
+ #TODO: add authentication option
3
+ {
4
+ "Version": "2012-10-17",
5
+ "Id": "Policy1477442935689",
6
+ "Statement": [
7
+ {
8
+ "Sid": "Stmt1477442933718",
9
+ "Effect": "Allow",
10
+ "Principal": "*",
11
+ "Action": "s3:PutObject",
12
+ "Resource": "arn:aws:s3:::<BUCKET_NAME>/*"
13
+ }
14
+ ]
15
+ }
@@ -1,2 +1,5 @@
1
1
  ---
2
2
  backups_enabled: true
3
+ s3_db_backup_bucket: disabled
4
+ s3_db_backup_prefix: "{{project_name}}/{{rails_env}}"
5
+ database_user: "{{project_name}}"
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  - name: postgresql restart
3
3
  service: name=postgresql state=restarted
4
- sudo: yes
4
+ become: yes
@@ -1,7 +1,2 @@
1
1
  ---
2
- dependencies:
3
- - {
4
- role: zenoamaro.postgresql,
5
- sudo: true,
6
- notify: postgresql restart
7
- }
2
+ dependencies:
@@ -18,12 +18,6 @@
18
18
  dest: "/u/apps/{{project_name}}/shared/db/backup.sh"
19
19
  mode: 0755
20
20
 
21
- - name: Remove old backup cron job because it had the wrong name
22
- cron:
23
- user: "{{deploy_user}}"
24
- name: "check dirs"
25
- state: "absent"
26
-
27
21
  - name: Install backup cron job
28
22
  when: backups_enabled
29
23
  cron:
@@ -31,3 +25,11 @@
31
25
  name: "Hourly backups"
32
26
  minute: "0"
33
27
  job: "/u/apps/{{project_name}}/shared/db/backup.sh"
28
+ state: "present"
29
+
30
+ - name: disable backup cron job
31
+ when: not backups_enabled
32
+ cron:
33
+ user: "{{deploy_user}}"
34
+ name: "Hourly backups"
35
+ state: "absent"
@@ -1,11 +1,64 @@
1
1
  ---
2
+ - set_fact: postgresql_installed="true"
3
+
4
+ - name: Add PostgreSQL official APT repository
5
+ ansible.builtin.deb822_repository:
6
+ name: postgresql
7
+ types: [deb]
8
+ uris: "http://apt.postgresql.org/pub/repos/apt/"
9
+ suites: [ "{{ ansible_facts['distribution_release'] }}-pgdg" ]
10
+ components: [main]
11
+ signed_by: https://www.postgresql.org/media/keys/ACCC4CF8.asc
12
+ state: present
13
+ enabled: true
14
+ register: pg_apt
15
+
16
+ - name: Update package cache if PG repo was added
17
+ become: yes
18
+ when: pg_apt.changed
19
+ apt:
20
+ update_cache: yes
21
+
22
+ - name: Install PostgreSQL
23
+ become: yes
24
+ apt:
25
+ name: "{{item}}"
26
+ state: latest
27
+ update_cache: yes
28
+ cache_valid_time: 3600
29
+ with_items:
30
+ - "postgresql-{{postgresql_version}}"
31
+ - "postgresql-client-{{postgresql_version}}"
32
+ - "libpq-dev"
33
+ tags:
34
+ - postgresql
35
+ - db
36
+ - deps
37
+
38
+ - name: "Detect python3"
39
+ shell: "which python3"
40
+ register: is_python3
41
+
42
+ - name: Ensure pip is installed
43
+ apt:
44
+ name: python3-pip
45
+ state: present
46
+ update_cache: yes
47
+ cache_valid_time: 3600
48
+
49
+ - name: Install psycopg2
50
+ become: yes
51
+ pip:
52
+ name: psycopg2
53
+ break_system_packages: true
54
+
2
55
  - name: Create postgresql user
3
56
  postgresql_user:
4
57
  name: "{{database_user}}"
5
58
  password: "{{database_password}}"
6
59
  state: present
7
- sudo: yes
8
- sudo_user: postgres
60
+ become: true
61
+ become_user: postgres
9
62
 
10
63
  - name: Create postgresql database
11
64
  postgresql_db:
@@ -13,8 +66,8 @@
13
66
  owner: "{{database_user}}"
14
67
  template: template1
15
68
  state: present
16
- sudo: yes
17
- sudo_user: postgres
69
+ become: true
70
+ become_user: postgres
18
71
 
19
72
  - name: Grant all privileges on database to user
20
73
  postgresql_privs:
@@ -23,15 +76,42 @@
23
76
  roles: "{{database_user}}"
24
77
  state: present
25
78
  type: database
26
- sudo: yes
27
- sudo_user: postgres
79
+ become: true
80
+ become_user: postgres
28
81
 
29
82
  - name: "Enable postgres hstore"
30
- sudo: yes
31
- sudo_user: postgres
83
+ become: true
84
+ become_user: postgres
32
85
  postgresql_ext:
33
86
  db: "{{database_name}}"
34
87
  name: hstore
35
88
  state: present
36
89
 
37
- - include: backups.yml
90
+ - import_tasks: backups.yml
91
+ become: true
92
+
93
+ - name: Grab Psql version
94
+ shell: psql --version
95
+ register: stats_psql_version
96
+ when: send_stats == true and stats_url is defined and stats_api_key is defined
97
+ tags:
98
+ - maintenance
99
+ - stats
100
+
101
+ - name: Send Psql stats to URL
102
+ uri:
103
+ url: "{{stats_url}}"
104
+ method: POST
105
+ headers:
106
+ X-API-Version: 1
107
+ X-Client-Api-key: "{{stats_api_key}}"
108
+ body_format: json
109
+ body:
110
+ client_stat:
111
+ stat_type: psql_version
112
+ value: "{{stats_psql_version.stdout}}"
113
+ hostname: "{{hostname}}"
114
+ when: send_stats == true and stats_url is defined and stats_api_key is defined
115
+ tags:
116
+ - maintenance
117
+ - stats
@@ -6,6 +6,8 @@
6
6
  # Storage folder where to move backup files
7
7
  # Must contain backup.monthly backup.weekly backup.daily folders
8
8
  storage=/u/apps/{{project_name}}/shared/db/backups
9
+ bucket="{{s3_db_backup_bucket}}"
10
+ prefix="{{s3_db_backup_prefix}}"
9
11
 
10
12
  # Destination file names
11
13
  date_hourly=`date +"%Y%m%d%H%M"`
@@ -36,8 +38,21 @@ else
36
38
  destination=backup.hourly/$filename
37
39
  fi
38
40
 
39
- #destination is set so actually do the backup
40
- $(PGPASSWORD={{database_password}} pg_dump --verbose -Fc --host=localhost --username={{database_user}} --file $storage/$destination {{database_name}})
41
+ if [ "$bucket" != "disabled" ] ; then
42
+ if [ -f "$storage/latest.dump" ] ; then
43
+ if [ -f "$storage/latest-old.dump" ] ; then
44
+ rm "$storage/latest-old.dump"
45
+ fi
46
+ mv "$storage/latest.dump" "$storage/latest-old.dump"
47
+ fi
48
+
49
+ $(PGPASSWORD={{database_password}} pg_dump --verbose -Fc --host=localhost --username={{database_user}} --file $storage/latest.dump {{database_name}})
50
+
51
+ curl -XPUT -T "$storage/latest.dump" -H "Host: $bucket.s3.amazonaws.com" -H "x-amz-acl: bucket-owner-full-control" https://$bucket.s3.amazonaws.com/$prefix/$destination
52
+ else
53
+ #destination is set so actually do the backup
54
+ $(PGPASSWORD={{database_password}} pg_dump --verbose -Fc --host=localhost --username={{database_user}} --file $storage/$destination {{database_name}})
55
+ fi
41
56
 
42
57
  # then clean old ones
43
58
  # hourly - for 48 hours