|
1 | | -# -*- mode: yaml -*- |
2 | | - |
3 | | -{%- from "postgres/map.jinja" import postgres with context -%} |
4 | | -{%- from "postgres/macros.jinja" import format_state with context -%} |
5 | | - |
6 | | -{%- if postgres.use_upstream_repo %} |
7 | | - |
8 | 1 | include: |
9 | | - - postgres.upstream |
10 | | - |
11 | | -{%- endif %} |
12 | | - |
13 | | -### Installation states |
14 | | - |
15 | | -postgresql-server: |
16 | | - pkg.installed: |
17 | | - - name: {{ postgres.pkg }} |
18 | | -{%- if postgres.use_upstream_repo %} |
19 | | - - refresh: True |
20 | | - - require: |
21 | | - - pkgrepo: postgresql-repo |
22 | | -{%- endif %} |
23 | | - |
24 | | -# make sure the data directory and contents have been initialized |
25 | | -postgresql-cluster-prepared: |
26 | | - cmd.run: |
27 | | - - name: {{ postgres.prepare_cluster.command }} |
28 | | - - cwd: / |
29 | | - - runas: {{ postgres.prepare_cluster.user }} |
30 | | - - env: {{ postgres.prepare_cluster.env|default({}) }} |
31 | | - - unless: |
32 | | - - {{ postgres.prepare_cluster.test }} |
33 | | - - require: |
34 | | - - pkg: postgresql-server |
35 | | - |
36 | | -postgresql-config-dir: |
37 | | - file.directory: |
38 | | - - name: {{ postgres.conf_dir }} |
39 | | - - user: {{ postgres.user }} |
40 | | - - group: {{ postgres.group }} |
41 | | - - makedirs: True |
42 | | - - require: |
43 | | - - cmd: postgresql-cluster-prepared |
44 | | - |
45 | | -{%- if postgres.postgresconf %} |
46 | | - |
47 | | -postgresql-conf: |
48 | | - file.blockreplace: |
49 | | - - name: {{ postgres.conf_dir }}/postgresql.conf |
50 | | - - marker_start: "# Managed by SaltStack: listen_addresses: please do not edit" |
51 | | - - marker_end: "# Managed by SaltStack: end of salt managed zone --" |
52 | | - - content: | |
53 | | - {{ postgres.postgresconf|indent(8) }} |
54 | | - - show_changes: True |
55 | | - - append_if_not_found: True |
56 | | - - backup: {{ postgres.postgresconf_backup }} |
57 | | - - watch_in: |
58 | | - - service: postgresql-running |
59 | | - - require: |
60 | | - - file: postgresql-config-dir |
61 | | - |
62 | | -{%- endif %} |
63 | | - |
64 | | -postgresql-pg_hba: |
65 | | - file.managed: |
66 | | - - name: {{ postgres.conf_dir }}/pg_hba.conf |
67 | | - - source: {{ postgres['pg_hba.conf'] }} |
68 | | - - template: jinja |
69 | | - - user: {{ postgres.user }} |
70 | | - - group: {{ postgres.group }} |
71 | | - - mode: 600 |
72 | | - - require: |
73 | | - - file: postgresql-config-dir |
74 | | - |
75 | | -postgresql-running: |
76 | | - service.running: |
77 | | - - name: {{ postgres.service }} |
78 | | - - enable: True |
79 | | - - reload: True |
80 | | - - watch: |
81 | | - - file: postgresql-pg_hba |
82 | | - |
83 | | -postgresql-extra-pkgs-installed: |
84 | | - pkg.installed: |
85 | | - - pkgs: {{ postgres.pkgs_extra }} |
86 | | - |
87 | | -### User states |
88 | | - |
89 | | -{%- for name, user in postgres.users|dictsort() %} |
90 | | - |
91 | | -{{ format_state(name, 'postgres_user', user) }} |
92 | | - - require: |
93 | | - - service: postgresql-running |
94 | | - {%- if 'db_user' in user %} |
95 | | - - postgres_user: postgres_user-{{ user.db_user }} |
96 | | - {%- endif %} |
97 | | - |
98 | | -{%- endfor %} |
99 | | - |
100 | | -### Tablespace states |
101 | | - |
102 | | -{%- for name, tblspace in postgres.tablespaces|dictsort() %} |
103 | | - |
104 | | -postgres_tablespace-dir-{{ tblspace.directory}}: |
105 | | - file.directory: |
106 | | - - name: {{ tblspace.directory }} |
107 | | - - user: {{ postgres.user }} |
108 | | - - group: {{ postgres.group }} |
109 | | - - mode: 700 |
110 | | - - makedirs: True |
111 | | - - recurse: |
112 | | - - user |
113 | | - - group |
114 | | - |
115 | | -{{ format_state(name, 'postgres_tablespace', tblspace) }} |
116 | | - - require: |
117 | | - - file: postgres_tablespace-dir-{{ tblspace.directory }} |
118 | | - {%- if 'owner' in tblspace %} |
119 | | - - postgres_user: postgres_user-{{ tblspace.owner }} |
120 | | - {%- endif %} |
121 | | - - service: postgresql-running |
122 | | - |
123 | | -{%- endfor %} |
124 | | - |
125 | | -### Database states |
126 | | - |
127 | | -{%- for name, db in postgres.databases|dictsort() %} |
128 | | - |
129 | | -{{ format_state(name, 'postgres_database', db) }} |
130 | | - - require: |
131 | | - - service: postgresql-running |
132 | | - {%- if 'db_user' in db %} |
133 | | - - postgres_user: postgres_user-{{ db.db_user }} |
134 | | - {%- endif %} |
135 | | - {%- if 'owner' in db %} |
136 | | - - postgres_user: postgres_user-{{ db.owner }} |
137 | | - {%- endif %} |
138 | | - {%- if 'tablespace' in db %} |
139 | | - - postgres_tablespace: postgres_tablespace-{{ db.tablespace }} |
140 | | - {%- endif %} |
141 | | - |
142 | | -{%- endfor %} |
143 | | - |
144 | | -### Schema states |
145 | | - |
146 | | -{%- for name, schema in postgres.schemas|dictsort() %} |
147 | | - |
148 | | -{{ format_state(name, 'postgres_schema', schema) }} |
149 | | - - require: |
150 | | - - service: postgresql-running |
151 | | - {%- if 'db_user' in schema %} |
152 | | - - postgres_user: postgres_user-{{ schema.db_user }} |
153 | | - {%- endif %} |
154 | | - {%- if 'dbname' in schema %} |
155 | | - - postgres_database: postgres_database-{{ schema.dbname }} |
156 | | - {%- endif %} |
157 | | - {%- if 'owner' in schema %} |
158 | | - - postgres_user: postgres_user-{{ schema.owner }} |
159 | | - {%- endif %} |
160 | | - |
161 | | -{%- endfor %} |
162 | | - |
163 | | -### Extension states |
164 | | - |
165 | | -{%- for name, extension in postgres.extensions|dictsort() %} |
166 | | - |
167 | | -{{ format_state(name, 'postgres_extension', extension) }} |
168 | | - - require: |
169 | | - - service: postgresql-running |
170 | | - - pkg: postgresql-extra-pkgs-installed |
171 | | - {%- if 'db_user' in extension %} |
172 | | - - postgres_user: postgres_user-{{ extension.db_user }} |
173 | | - {%- endif %} |
174 | | - {%- if 'maintenance_db' in extension %} |
175 | | - - postgres_database: postgres_database-{{ extension.maintenance_db }} |
176 | | - {%- endif %} |
177 | | - {%- if 'schema' in extension %} |
178 | | - - postgres_schema: postgres_schema-{{ extension.schema }} |
179 | | - {%- endif %} |
180 | | - |
181 | | -{%- endfor %} |
| 2 | + - postgres.server |
| 3 | + - postgres.client |
0 commit comments