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'
|
ansible 'Ansible'
|
||||||
}
|
}
|
||||||
environment {
|
environment {
|
||||||
PSQL_PASSWORD = credentials('PSQL_pass')
|
PSQL_PASSWORD = "${params.DB_PASSWORD}"
|
||||||
VAULT_PASSWORD = credentials('ansible_vault_password')
|
VAULT_PASSWORD = credentials('ansible_vault_password')
|
||||||
}
|
}
|
||||||
parameters {
|
parameters {
|
||||||
string(name: 'DB_USER', defaultValue: 'postgres', description: 'Имя пользователя базы данных')
|
string(name: 'DB_USER', defaultValue: 'postgres', description: 'Имя пользователя базы данных')
|
||||||
|
password(name: 'DB_PASSWORD', defaultValue: '', description: 'Пароль для базы данных')
|
||||||
string(name: 'DB_NAME', defaultValue: 'mydb', description: 'Имя базы данных')
|
string(name: 'DB_NAME', defaultValue: 'mydb', description: 'Имя базы данных')
|
||||||
string(name: 'BACKUP_DIR', defaultValue: '/var/backups/postgresql', 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 {
|
stages {
|
||||||
stage('Clone repository') {
|
stage('Clone Repository') {
|
||||||
steps {
|
steps {
|
||||||
git branch: 'dev', url: 'http://192.168.0.70:3000/coursework/courseworkrep.git'
|
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 {
|
steps {
|
||||||
script {
|
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(
|
ansiblePlaybook(
|
||||||
playbook: 'playbooks/install_postgresql.yml',
|
playbook: 'playbooks/install_postgresql.yml',
|
||||||
inventory: "inventory.yml",
|
inventory: "inventory.yml",
|
||||||
extraVars: [
|
extraVars: [
|
||||||
postgres_user: params.DB_USER,
|
postgres_user: params.DB_USER,
|
||||||
postgres_password: PSQL_PASSWORD,
|
postgres_password: env.PSQL_PASSWORD,
|
||||||
postgres_db: params.DB_NAME,
|
postgres_db: params.DB_NAME,
|
||||||
backup_dir: params.BACKUP_DIR,
|
backup_dir: params.BACKUP_DIR,
|
||||||
ansible_ssh_private_key_file: env.DECRYPTED_KEY_FILE
|
ansible_ssh_private_key_file: env.DECRYPTED_KEY_FILE
|
||||||
|
@ -2,3 +2,4 @@
|
|||||||
inventory = inventory.yml
|
inventory = inventory.yml
|
||||||
roles_path = ./roles
|
roles_path = ./roles
|
||||||
force_color = true
|
force_color = true
|
||||||
|
interpreter_python = /usr/bin/python3
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
all:
|
all:
|
||||||
children:
|
|
||||||
postgres_servers:
|
|
||||||
hosts:
|
hosts:
|
||||||
192.168.0.71:
|
192.168.0.71:
|
||||||
ansible_user: ansible
|
ansible_user: ansible
|
@ -1,4 +1,4 @@
|
|||||||
- name: Configure postgresql.conf with template
|
- name: Configure postgresql.conf
|
||||||
template:
|
template:
|
||||||
src: postgresql.conf.j2
|
src: postgresql.conf.j2
|
||||||
dest: /var/lib/pgsql/data/postgresql.conf
|
dest: /var/lib/pgsql/data/postgresql.conf
|
||||||
@ -7,7 +7,7 @@
|
|||||||
mode: '0644'
|
mode: '0644'
|
||||||
notify: Restart PostgreSQL
|
notify: Restart PostgreSQL
|
||||||
|
|
||||||
- name: Configure pg_hba.conf with template
|
- name: Configure pg_hba.conf
|
||||||
template:
|
template:
|
||||||
src: pg_hba.conf.j2
|
src: pg_hba.conf.j2
|
||||||
dest: /var/lib/pgsql/data/pg_hba.conf
|
dest: /var/lib/pgsql/data/pg_hba.conf
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
encoding: UTF8
|
encoding: UTF8
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: Create contacts table in PostgreSQL
|
- name: Create contacts table
|
||||||
community.postgresql.postgresql_query:
|
community.postgresql.postgresql_query:
|
||||||
db: '{{ postgres_db }}'
|
db: '{{ postgres_db }}'
|
||||||
query: |
|
query: |
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
- name: Insert data into PostgreSQL database idempotently
|
- name: Insert data into PostgreSQL database
|
||||||
community.postgresql.postgresql_query:
|
community.postgresql.postgresql_query:
|
||||||
db: '{{ postgres_db }}'
|
db: '{{ postgres_db }}'
|
||||||
query: |
|
query: |
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
state: enabled
|
state: enabled
|
||||||
become: true
|
become: true
|
||||||
|
|
||||||
- name: Reload firewall using command
|
- name: Reload firewalld
|
||||||
command: firewall-cmd --reload
|
systemd:
|
||||||
|
name: firewalld
|
||||||
|
state: reloaded
|
||||||
become: true
|
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 }}
|
||||||
max_connections = {{ postgres_max_connections | default(100) }}
|
shared_buffers = {{ postgres_shared_buffers }}
|
||||||
shared_buffers = {{ postgres_shared_buffers | default("128MB") }}
|
effective_cache_size = {{ postgres_effective_cache_size }}
|
||||||
effective_cache_size = {{ postgres_effective_cache_size | default("4GB") }}
|
maintenance_work_mem = {{ postgres_maintenance_work_mem }}
|
||||||
maintenance_work_mem = {{ postgres_maintenance_work_mem | default("64MB") }}
|
checkpoint_completion_target = {{ postgres_checkpoint_completion_target }}
|
||||||
checkpoint_completion_target = {{ postgres_checkpoint_completion_target | default(0.7) }}
|
wal_buffers = {{ postgres_wal_buffers }}
|
||||||
wal_buffers = {{ postgres_wal_buffers | default("16MB") }}
|
default_statistics_target = {{ postgres_default_statistics_target }}
|
||||||
default_statistics_target = {{ postgres_default_statistics_target | default(100) }}
|
|
||||||
|
@ -8,3 +8,11 @@ postgres_hba_entries:
|
|||||||
backup_dir: "/var/backups/postgresql"
|
backup_dir: "/var/backups/postgresql"
|
||||||
postgres_user: "postgres"
|
postgres_user: "postgres"
|
||||||
postgres_db: "mydb"
|
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