fixed install playbook
This commit is contained in:
parent
67166656f3
commit
cf04997289
@ -6,83 +6,93 @@
|
|||||||
postgres_user: "{{ postgres_user }}"
|
postgres_user: "{{ postgres_user }}"
|
||||||
postgres_password: "{{ postgres_password }}"
|
postgres_password: "{{ postgres_password }}"
|
||||||
postgres_db: "{{ postgres_db }}"
|
postgres_db: "{{ postgres_db }}"
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
|
|
||||||
- name: Update zypper
|
- name: Update zypper
|
||||||
command: zypper refresh
|
command: zypper refresh
|
||||||
register: zypper_refresh
|
register: zypper_refresh
|
||||||
changed_when: "'Refreshing' in zypper_refresh.stdout"
|
changed_when: "'Refreshing' in zypper_refresh.stdout"
|
||||||
|
|
||||||
- name: Update System
|
- name: Update System
|
||||||
zypper:
|
zypper:
|
||||||
name: '*'
|
name: '*'
|
||||||
state: latest
|
state: latest
|
||||||
when: zypper_refresh.changed
|
when: zypper_refresh.changed
|
||||||
|
|
||||||
- name: Update PostgreSQL package
|
- name: Update PostgreSQL package
|
||||||
zypper:
|
zypper:
|
||||||
name:
|
name:
|
||||||
- postgresql-server
|
- postgresql-server
|
||||||
- postgresql-contrib
|
- postgresql-contrib
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: PostgreSQL initdb
|
- name: PostgreSQL initdb
|
||||||
command: sudo -u postgres initdb -D /var/lib/pgsql/data
|
command: sudo -u postgres initdb -D /var/lib/pgsql/data
|
||||||
args:
|
args:
|
||||||
creates: /var/lib/pgsql/data/PG_VERSION
|
creates: /var/lib/pgsql/data/PG_VERSION
|
||||||
|
|
||||||
- name: Systemctl start and enable PostgreSQL
|
- name: Systemctl start and enable PostgreSQL
|
||||||
service:
|
service:
|
||||||
name: postgresql
|
name: postgresql
|
||||||
state: started
|
state: started
|
||||||
enabled: yes
|
enabled: yes
|
||||||
|
|
||||||
- name: python3-psycopg2 install
|
- name: python3-psycopg2 install
|
||||||
zypper:
|
zypper:
|
||||||
name: python3-psycopg2
|
name: python3-psycopg2
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: Change listen_addresses in postgresql.conf
|
- name: Change listen_addresses in postgresql.conf
|
||||||
lineinfile:
|
lineinfile:
|
||||||
path: /var/lib/pgsql/data/postgresql.conf
|
path: /var/lib/pgsql/data/postgresql.conf
|
||||||
regexp: '^#?listen_addresses\s*='
|
regexp: '^#?listen_addresses\s*='
|
||||||
line: "listen_addresses = '*'"
|
line: "listen_addresses = '*'"
|
||||||
notify: Restart PostgreSQL
|
notify: Restart PostgreSQL
|
||||||
|
|
||||||
- name: Change pg_hba.conf
|
- name: Change pg_hba.conf
|
||||||
lineinfile:
|
lineinfile:
|
||||||
path: /var/lib/pgsql/data/pg_hba.conf
|
path: /var/lib/pgsql/data/pg_hba.conf
|
||||||
regexp: '^host\s+all\s+all\s+0\.0\.0\.0/0\s+md5'
|
regexp: '^host\s+all\s+all\s+0\.0\.0\.0/0\s+md5'
|
||||||
line: "host all all 0.0.0.0/0 md5"
|
line: "host all all 0.0.0.0/0 md5"
|
||||||
notify: Restart PostgreSQL
|
notify: Restart PostgreSQL
|
||||||
|
|
||||||
- name: Create User PostgreSQL
|
- name: Create User PostgreSQL
|
||||||
community.postgresql.postgresql_user:
|
community.postgresql.postgresql_user:
|
||||||
name: "{{ postgres_user }}"
|
name: "{{ postgres_user }}"
|
||||||
password: "{{ postgres_password }}"
|
password: "{{ postgres_password }}"
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: Create Base PostgreSQL
|
- name: Create Base PostgreSQL
|
||||||
community.postgresql.postgresql_db:
|
community.postgresql.postgresql_db:
|
||||||
name: "{{ postgres_db }}"
|
name: "{{ postgres_db }}"
|
||||||
owner: "{{ postgres_user }}"
|
owner: "{{ postgres_user }}"
|
||||||
encoding: UTF8
|
encoding: UTF8
|
||||||
state: present
|
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 в файрволе
|
- name: Открыть порт PostgreSQL 5432 в файрволе
|
||||||
command: firewall-cmd --add-port=5432/tcp --permanent
|
command: firewall-cmd --add-port=5432/tcp --permanent
|
||||||
become: yes
|
become: yes
|
||||||
|
|
||||||
|
|
||||||
- name: Перезагрузить файрвол для применения изменений
|
- name: Перезагрузить файрвол для применения изменений
|
||||||
command: firewall-cmd --reload
|
command: firewall-cmd --reload
|
||||||
become: yes
|
become: yes
|
||||||
|
|
||||||
handlers:
|
handlers:
|
||||||
- name: Restart PostgreSQL
|
- name: Restart PostgreSQL
|
||||||
service:
|
service:
|
||||||
name: postgresql
|
name: postgresql
|
||||||
state: restarted
|
state: restarted
|
||||||
|
|
@ -2,14 +2,14 @@ pipeline {
|
|||||||
agent any
|
agent any
|
||||||
|
|
||||||
parameters {
|
parameters {
|
||||||
string(name: 'TARGET_IP', defaultValue: '192.168.0.72')
|
string(name: 'TARGET_IP', defaultValue: '192.168.0.72', description: 'IP адрес машины для установки PostgreSQL')
|
||||||
string(name: 'DB_USER', defaultValue: 'myuser')
|
string(name: 'DB_USER', defaultValue: 'myuser', description: 'Имя пользователя для базы данных PostgreSQL')
|
||||||
string(name: 'DB_NAME', defaultValue: 'mydatabase')
|
string(name: 'DB_NAME', defaultValue: 'mydatabase', description: 'Имя базы данных PostgreSQL')
|
||||||
string(name: 'BACKUP_DIR', defaultValue: '/var/backups/postgresql')
|
string(name: 'BACKUP_DIR', defaultValue: '/var/backups/postgresql', description: 'Путь для сохранения резервных копий')
|
||||||
}
|
}
|
||||||
|
|
||||||
environment {
|
environment {
|
||||||
ANSIBLE_HOST_KEY_CHECKING = 'False'
|
ANSIBLE_HOST_KEY_CHECKING = 'False'
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
|
Loading…
Reference in New Issue
Block a user