From cf04997289c1f5be77b61a905ba8dc58a644023e Mon Sep 17 00:00:00 2001 From: dima Date: Sun, 20 Oct 2024 13:35:21 +0300 Subject: [PATCH] fixed install playbook --- install_postgresql.yml | 42 ++++++++++++++++++++++++++---------------- pipeline.groovy | 10 +++++----- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/install_postgresql.yml b/install_postgresql.yml index 080459d..96f986e 100644 --- a/install_postgresql.yml +++ b/install_postgresql.yml @@ -6,83 +6,93 @@ postgres_user: "{{ postgres_user }}" postgres_password: "{{ postgres_password }}" postgres_db: "{{ postgres_db }}" - + tasks: - + - name: Update zypper command: zypper refresh register: zypper_refresh changed_when: "'Refreshing' in zypper_refresh.stdout" - + - name: Update System zypper: name: '*' state: latest when: zypper_refresh.changed - + - name: Update PostgreSQL package zypper: name: - postgresql-server - postgresql-contrib state: present - + - name: PostgreSQL initdb command: sudo -u postgres initdb -D /var/lib/pgsql/data args: creates: /var/lib/pgsql/data/PG_VERSION - + - name: Systemctl start and enable PostgreSQL service: name: postgresql state: started enabled: yes - + - name: python3-psycopg2 install zypper: name: python3-psycopg2 state: present - + - name: Change listen_addresses in postgresql.conf lineinfile: path: /var/lib/pgsql/data/postgresql.conf regexp: '^#?listen_addresses\s*=' line: "listen_addresses = '*'" notify: Restart PostgreSQL - + - name: Change pg_hba.conf lineinfile: path: /var/lib/pgsql/data/pg_hba.conf regexp: '^host\s+all\s+all\s+0\.0\.0\.0/0\s+md5' line: "host all all 0.0.0.0/0 md5" notify: Restart PostgreSQL - + - name: Create User PostgreSQL community.postgresql.postgresql_user: name: "{{ postgres_user }}" password: "{{ postgres_password }}" state: present - + - name: Create Base PostgreSQL community.postgresql.postgresql_db: name: "{{ postgres_db }}" owner: "{{ postgres_user }}" encoding: UTF8 state: present - + + + - name: Create a table for storing names and phone numbers + community.postgresql.postgresql_query: + db: "{{ postgres_db }}" + query: > + CREATE TABLE IF NOT EXISTS contacts ( + id SERIAL PRIMARY KEY, + name VARCHAR(100), + phone_number VARCHAR(15) + ); + login_user: "{{ postgres_user }}" + login_password: "{{ postgres_password }}" - name: Открыть порт PostgreSQL 5432 в файрволе command: firewall-cmd --add-port=5432/tcp --permanent become: yes - - + - name: Перезагрузить файрвол для применения изменений command: firewall-cmd --reload become: yes - + handlers: - name: Restart PostgreSQL service: name: postgresql state: restarted - \ No newline at end of file diff --git a/pipeline.groovy b/pipeline.groovy index 490340f..a31e4ba 100644 --- a/pipeline.groovy +++ b/pipeline.groovy @@ -2,14 +2,14 @@ pipeline { agent any parameters { - string(name: 'TARGET_IP', defaultValue: '192.168.0.72') - string(name: 'DB_USER', defaultValue: 'myuser') - string(name: 'DB_NAME', defaultValue: 'mydatabase') - string(name: 'BACKUP_DIR', defaultValue: '/var/backups/postgresql') + string(name: 'TARGET_IP', defaultValue: '192.168.0.72', description: 'IP адрес машины для установки PostgreSQL') + string(name: 'DB_USER', defaultValue: 'myuser', description: 'Имя пользователя для базы данных PostgreSQL') + string(name: 'DB_NAME', defaultValue: 'mydatabase', description: 'Имя базы данных PostgreSQL') + string(name: 'BACKUP_DIR', defaultValue: '/var/backups/postgresql', description: 'Путь для сохранения резервных копий') } environment { - ANSIBLE_HOST_KEY_CHECKING = 'False' + ANSIBLE_HOST_KEY_CHECKING = 'False' } stages {