Compare commits
4 Commits
293bf6d004
...
main
Author | SHA1 | Date | |
---|---|---|---|
b7fab03b1f | |||
08cc9fc069 | |||
54f9f8df11 | |||
3bf99fc8f0 |
32
Jenkinsfile
vendored
32
Jenkinsfile
vendored
@ -7,17 +7,26 @@ pipeline {
|
||||
ansible 'Ansible'
|
||||
}
|
||||
environment {
|
||||
PSQL_PASSWORD = credentials('PSQL_pass')
|
||||
PSQL_PASSWORD = "${params.DB_PASSWORD}"
|
||||
VAULT_PASSWORD = credentials('ansible_vault_password')
|
||||
}
|
||||
parameters {
|
||||
string(name: 'DB_USER', defaultValue: 'postgres', description: 'Имя пользователя базы данных')
|
||||
password(name: 'DB_PASSWORD', defaultValue: '', description: 'Пароль для базы данных')
|
||||
string(name: 'DB_NAME', defaultValue: 'mydb', description: 'Имя базы данных')
|
||||
string(name: 'BACKUP_DIR', defaultValue: '/var/backups/postgresql', description: 'Директория для бэкапа')
|
||||
string(name: 'TASKS', defaultValue: '', description: 'Список тегов задач для выполнения (setup,firewall,init,configure,database,insert,user,backup)')
|
||||
|
||||
booleanParam(name: 'TASK_SETUP', defaultValue: false, description: 'Setup')
|
||||
booleanParam(name: 'TASK_INIT', defaultValue: false, description: 'Init')
|
||||
booleanParam(name: 'TASK_CONFIGURE', defaultValue: false, description: 'Configure')
|
||||
booleanParam(name: 'TASK_USERS', defaultValue: false, description: 'Users')
|
||||
booleanParam(name: 'TASK_DATABASE', defaultValue: false, description: 'Database')
|
||||
booleanParam(name: 'TASK_INSERT', defaultValue: false, description: 'Insert')
|
||||
booleanParam(name: 'TASK_FIREWALL', defaultValue: false, description: 'Firewall')
|
||||
booleanParam(name: 'TASK_BACKUP', defaultValue: false, description: 'Backup')
|
||||
}
|
||||
stages {
|
||||
stage('Clone repository') {
|
||||
stage('Clone Repository') {
|
||||
steps {
|
||||
git branch: 'dev', url: 'http://192.168.0.70:3000/coursework/courseworkrep.git'
|
||||
}
|
||||
@ -41,17 +50,28 @@ pipeline {
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Run PostgreSQL Playbook') {
|
||||
stage('Run Ansible Playbook') {
|
||||
steps {
|
||||
script {
|
||||
def tagsString = params.TASKS ? params.TASKS.split(',').join(',') : ''
|
||||
def selectedTags = []
|
||||
|
||||
if (params.TASK_SETUP) selectedTags << 'setup'
|
||||
if (params.TASK_INIT) selectedTags << 'init'
|
||||
if (params.TASK_CONFIGURE) selectedTags << 'configure'
|
||||
if (params.TASK_USERS) selectedTags << 'users'
|
||||
if (params.TASK_DATABASE) selectedTags << 'database'
|
||||
if (params.TASK_INSERT) selectedTags << 'insert'
|
||||
if (params.TASK_FIREWALL) selectedTags << 'firewall'
|
||||
if (params.TASK_BACKUP) selectedTags << 'backup'
|
||||
|
||||
def tagsString = selectedTags.join(',')
|
||||
|
||||
ansiblePlaybook(
|
||||
playbook: 'playbooks/install_postgresql.yml',
|
||||
inventory: "inventory.yml",
|
||||
extraVars: [
|
||||
postgres_user: params.DB_USER,
|
||||
postgres_password: PSQL_PASSWORD,
|
||||
postgres_password: env.PSQL_PASSWORD,
|
||||
postgres_db: params.DB_NAME,
|
||||
backup_dir: params.BACKUP_DIR,
|
||||
ansible_ssh_private_key_file: env.DECRYPTED_KEY_FILE
|
||||
|
@ -2,3 +2,4 @@
|
||||
inventory = inventory.yml
|
||||
roles_path = ./roles
|
||||
force_color = true
|
||||
interpreter_python = /usr/bin/python3
|
||||
|
@ -1,6 +1,4 @@
|
||||
all:
|
||||
children:
|
||||
postgres_servers:
|
||||
hosts:
|
||||
192.168.0.71:
|
||||
ansible_user: ansible
|
@ -1,4 +1,4 @@
|
||||
- name: Configure postgresql.conf with template
|
||||
- name: Configure postgresql.conf
|
||||
template:
|
||||
src: postgresql.conf.j2
|
||||
dest: /var/lib/pgsql/data/postgresql.conf
|
||||
@ -7,7 +7,7 @@
|
||||
mode: '0644'
|
||||
notify: Restart PostgreSQL
|
||||
|
||||
- name: Configure pg_hba.conf with template
|
||||
- name: Configure pg_hba.conf
|
||||
template:
|
||||
src: pg_hba.conf.j2
|
||||
dest: /var/lib/pgsql/data/pg_hba.conf
|
||||
|
@ -5,7 +5,7 @@
|
||||
encoding: UTF8
|
||||
state: present
|
||||
|
||||
- name: Create contacts table in PostgreSQL
|
||||
- name: Create contacts table
|
||||
community.postgresql.postgresql_query:
|
||||
db: '{{ postgres_db }}'
|
||||
query: |
|
||||
|
@ -1,4 +1,4 @@
|
||||
- name: Insert data into PostgreSQL database idempotently
|
||||
- name: Insert data into PostgreSQL database
|
||||
community.postgresql.postgresql_query:
|
||||
db: '{{ postgres_db }}'
|
||||
query: |
|
||||
|
@ -5,6 +5,8 @@
|
||||
state: enabled
|
||||
become: true
|
||||
|
||||
- name: Reload firewall using command
|
||||
command: firewall-cmd --reload
|
||||
- name: Reload firewalld
|
||||
systemd:
|
||||
name: firewalld
|
||||
state: reloaded
|
||||
become: true
|
||||
|
@ -1,12 +1,11 @@
|
||||
listen_addresses = '{{ postgres_listen_addresses | default("*") }}'
|
||||
listen_addresses = '{{ postgres_listen_addresses }}'
|
||||
|
||||
port = {{ postgres_port | default(5432) }}
|
||||
port = {{ postgres_port }}
|
||||
|
||||
|
||||
max_connections = {{ postgres_max_connections | default(100) }}
|
||||
shared_buffers = {{ postgres_shared_buffers | default("128MB") }}
|
||||
effective_cache_size = {{ postgres_effective_cache_size | default("4GB") }}
|
||||
maintenance_work_mem = {{ postgres_maintenance_work_mem | default("64MB") }}
|
||||
checkpoint_completion_target = {{ postgres_checkpoint_completion_target | default(0.7) }}
|
||||
wal_buffers = {{ postgres_wal_buffers | default("16MB") }}
|
||||
default_statistics_target = {{ postgres_default_statistics_target | default(100) }}
|
||||
max_connections = {{ postgres_max_connections }}
|
||||
shared_buffers = {{ postgres_shared_buffers }}
|
||||
effective_cache_size = {{ postgres_effective_cache_size }}
|
||||
maintenance_work_mem = {{ postgres_maintenance_work_mem }}
|
||||
checkpoint_completion_target = {{ postgres_checkpoint_completion_target }}
|
||||
wal_buffers = {{ postgres_wal_buffers }}
|
||||
default_statistics_target = {{ postgres_default_statistics_target }}
|
||||
|
@ -8,3 +8,11 @@ postgres_hba_entries:
|
||||
backup_dir: "/var/backups/postgresql"
|
||||
postgres_user: "postgres"
|
||||
postgres_db: "mydb"
|
||||
|
||||
postgres_max_connections: 100
|
||||
postgres_shared_buffers: '128MB'
|
||||
postgres_effective_cache_size: '4GB'
|
||||
postgres_maintenance_work_mem: '64MB'
|
||||
postgres_checkpoint_completion_target: 0.7
|
||||
postgres_wal_buffers: '16MB'
|
||||
postgres_default_statistics_target: 100
|
Reference in New Issue
Block a user