summaryrefslogtreecommitdiffstats
path: root/src/tests/salt-test-server/salt/postgres.sls
blob: 26fc4e615096932819c1aa5fccc411356523216b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
postgresql:
    # Install postgres and make sure it is running and starts on boot
    pkg:
        - installed
    # Only try to start service after DB has been initialized (will fail otherwise)
    service:
        - name: postgresql
        - running
        - enable: True

postgres_set_interface:
    file.sed:
        - name: /etc/postgresql/9.4/main/postgresql.conf
        - before: ^\#listen_addresses = 'localhost'
        - after: listen_addresses = '*'

postgres_password_auth:
    # Add authentication from anywhere
    file.append:
        - name: /etc/postgresql/9.4/main/pg_hba.conf
        - text:
            - host    radius      radius        0.0.0.0/0            md5

postgres_restart:
    # Restart postgres after changes to the config file (reload isn't enough)
    cmd.wait:
        - cwd: /
        - name: service postgresql restart
        - require:
            - pkg: postgresql
            - file: postgres_password_auth
            - file: postgres_set_interface
        - watch:
            - file: /etc/postgresql/9.4/main/postgresql.conf
            - file: /etc/postgresql/9.4/main/pg_hba.conf

# Copy DB schema file
/salt/postgres/schema.sql:
    file.managed:
        - source: salt://postgres/schema.sql
        - makedirs: true

# Copy DB setup script
/salt/postgres/setup.sql:
    file.managed:
        - source: salt://postgres/setup.sql
        - makedirs: true

# Create DB
create_db:
    cmd.run:
        - cwd: /
        - name: createdb radius
        - user: postgres
        - unless: psql --list | grep radius

# Create FreeRADIUS schema
psql radius < /salt/postgres/schema.sql:
    cmd.run:
        - user: postgres
        - unless: "echo '\\dt public.*' | psql radius | grep radacct;"
        - require:
            - file: /salt/postgres/schema.sql

# Setup DB access
psql radius < /salt/postgres/setup.sql:
    cmd.run:
        - user: postgres
        - unless: "echo '\\du' | psql radius | grep radius"
        - require:
            - file: /salt/postgres/setup.sql