init
This commit is contained in:
commit
04afd73ef6
9 changed files with 126 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
inventory.ini
|
7
inventory.tpl.ini
Normal file
7
inventory.tpl.ini
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
app-1 ansible_host=localhost ansible_user=root ansible_port=22 ansible_python_interpreter=python3
|
||||||
|
|
||||||
|
[app]
|
||||||
|
app-1
|
||||||
|
|
||||||
|
[db]
|
||||||
|
app-1
|
18
playbook.yml
Normal file
18
playbook.yml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
---
|
||||||
|
- hosts: app
|
||||||
|
become: yes
|
||||||
|
roles:
|
||||||
|
- app
|
||||||
|
tags:
|
||||||
|
- app
|
||||||
|
|
||||||
|
- hosts: db
|
||||||
|
become: yes
|
||||||
|
roles:
|
||||||
|
- pg
|
||||||
|
vars:
|
||||||
|
- db_name: "nativecloud"
|
||||||
|
- db_password: "password"
|
||||||
|
- db_user: "nativecloud"
|
||||||
|
tags:
|
||||||
|
- pg
|
8
roles/app/tasks/Rocky-9.yml
Normal file
8
roles/app/tasks/Rocky-9.yml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
---
|
||||||
|
- name: Install postgresql-server package
|
||||||
|
package:
|
||||||
|
name: [
|
||||||
|
gcc,
|
||||||
|
python3-devel,
|
||||||
|
]
|
||||||
|
state: present
|
2
roles/app/tasks/main.yml
Normal file
2
roles/app/tasks/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
---
|
||||||
|
- include_tasks: "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
|
10
roles/pg/handlers/main.yml
Normal file
10
roles/pg/handlers/main.yml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
---
|
||||||
|
- name: restart postgres
|
||||||
|
service:
|
||||||
|
name: postgresql
|
||||||
|
state: restarted
|
||||||
|
|
||||||
|
- name: reload postgresql
|
||||||
|
service:
|
||||||
|
name: postgresql
|
||||||
|
state: reloaded
|
52
roles/pg/tasks/Rocky-9.yml
Normal file
52
roles/pg/tasks/Rocky-9.yml
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
- name: Install postgresql-server package
|
||||||
|
package:
|
||||||
|
name: [
|
||||||
|
postgresql-server,
|
||||||
|
python3-psycopg2
|
||||||
|
]
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: initialize postgresql
|
||||||
|
command: postgresql-setup initdb
|
||||||
|
args:
|
||||||
|
creates: /var/lib/pgsql/data/pg_hba.conf
|
||||||
|
notify:
|
||||||
|
- reload postgresql
|
||||||
|
|
||||||
|
- name: configure pg_hba.conf
|
||||||
|
copy:
|
||||||
|
dest: /var/lib/pgsql/data/pg_hba.conf
|
||||||
|
content: |
|
||||||
|
local koji koji trust
|
||||||
|
local all postgres peer
|
||||||
|
mode: preserve
|
||||||
|
notify:
|
||||||
|
- reload postgresql
|
||||||
|
|
||||||
|
- name: disable TCP/IP for postgres
|
||||||
|
lineinfile:
|
||||||
|
dest: /var/lib/pgsql/data/postgresql.conf
|
||||||
|
regexp: '^#listen_addresses'
|
||||||
|
line: "listen_addresses = ''"
|
||||||
|
notify:
|
||||||
|
- reload postgresql
|
||||||
|
|
||||||
|
# Note: this is not in the upstream documentation. It's still under discussion
|
||||||
|
# upstream, see
|
||||||
|
# https://lists.fedorahosted.org/archives/list/koji-devel@lists.fedorahosted.org/thread/NMDIDYS7CZWB3SMPT6UO2P5WGZXKIZVW/
|
||||||
|
- name: increase number of max connections
|
||||||
|
lineinfile:
|
||||||
|
dest: /var/lib/pgsql/data/postgresql.conf
|
||||||
|
regexp: '^max_connections'
|
||||||
|
line: "max_connections = 500"
|
||||||
|
notify:
|
||||||
|
- reload postgresql
|
||||||
|
when:
|
||||||
|
- ansible_os_family == "RedHat" and ansible_distribution_major_version|int > 7
|
||||||
|
# - ansible_os_family == "RedHat" and ansible_distribution_major_version|int > 7
|
||||||
|
|
||||||
|
- name: start postgresql
|
||||||
|
service:
|
||||||
|
name: postgresql
|
||||||
|
state: started
|
||||||
|
enabled: true
|
3
roles/pg/tasks/main.yml
Normal file
3
roles/pg/tasks/main.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
- include_tasks: "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
|
||||||
|
- include_tasks: postgres.yml
|
25
roles/pg/tasks/postgres.yml
Normal file
25
roles/pg/tasks/postgres.yml
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
---
|
||||||
|
- name: "Create app database"
|
||||||
|
postgresql_db:
|
||||||
|
state: present
|
||||||
|
name: "{{ db_name }}"
|
||||||
|
become: yes
|
||||||
|
become_user: postgres
|
||||||
|
|
||||||
|
- name: "Create db user"
|
||||||
|
postgresql_user:
|
||||||
|
state: present
|
||||||
|
name: "{{ db_user }}"
|
||||||
|
password: "{{ db_password }}"
|
||||||
|
become: yes
|
||||||
|
become_user: postgres
|
||||||
|
|
||||||
|
- name: "Grant db user access to app db"
|
||||||
|
postgresql_privs:
|
||||||
|
type: database
|
||||||
|
database: "{{ db_name }}"
|
||||||
|
roles: "{{ db_user }}"
|
||||||
|
grant_option: no
|
||||||
|
privs: all
|
||||||
|
become: yes
|
||||||
|
become_user: postgres
|
Loading…
Add table
Reference in a new issue