create ansible playbook
This commit is contained in:
parent
df1b0c06b0
commit
a1fe561618
2
hosts.ini
Normal file
2
hosts.ini
Normal file
@ -0,0 +1,2 @@
|
||||
[postgres_servers]
|
||||
192.168.0.72 ansible_user=root ansible_password='XSW@1qaz' ansible_connection=ssh
|
89
install_postgresql.yml
Normal file
89
install_postgresql.yml
Normal file
@ -0,0 +1,89 @@
|
||||
---
|
||||
- name: Установка и настройка PostgreSQL
|
||||
hosts: postgres_servers
|
||||
become: yes
|
||||
vars:
|
||||
postgres_user: myuser
|
||||
postgres_password: mypassword
|
||||
postgres_db: mydatabase
|
||||
tasks:
|
||||
|
||||
- name: Обновление zypper
|
||||
command: zypper refresh
|
||||
register: zypper_refresh
|
||||
changed_when: "'Refreshing' in zypper_refresh.stdout"
|
||||
|
||||
- name: Обновление системы
|
||||
zypper:
|
||||
name: '*'
|
||||
state: latest
|
||||
when: zypper_refresh.changed
|
||||
|
||||
- name: Установка пакетов PostgreSQL
|
||||
zypper:
|
||||
name:
|
||||
- postgresql-server
|
||||
- postgresql-contrib
|
||||
state: present
|
||||
|
||||
- name: Инициализация базы данных PostgreSQL
|
||||
command: /usr/bin/postgresql-setup initdb
|
||||
args:
|
||||
creates: /var/lib/pgsql/data/PG_VERSION
|
||||
when: ansible_facts['pkg_mgr'] == 'zypper'
|
||||
|
||||
- name: Обеспечение запуска и автозапуска службы PostgreSQL
|
||||
service:
|
||||
name: postgresql
|
||||
state: started
|
||||
enabled: yes
|
||||
|
||||
- name: Установка python
|
||||
zypper:
|
||||
name: python3-psycopg2
|
||||
state: present
|
||||
|
||||
- name: Настройка listen_addresses в postgresql.conf
|
||||
lineinfile:
|
||||
path: /var/lib/pgsql/data/postgresql.conf
|
||||
regexp: '^#?listen_addresses\s*='
|
||||
line: "listen_addresses = '*'"
|
||||
notify: Перезапуск PostgreSQL
|
||||
|
||||
- name: Настройка 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: Перезапуск PostgreSQL
|
||||
|
||||
- name: Создание пользователя PostgreSQL
|
||||
community.postgresql.postgresql_user:
|
||||
name: "{{ postgres_user }}"
|
||||
password: "{{ postgres_password }}"
|
||||
state: present
|
||||
|
||||
|
||||
- name: Создание базы данных PostgreSQL
|
||||
community.postgresql.postgresql_db:
|
||||
name: "{{ postgres_db }}"
|
||||
owner: "{{ postgres_user }}"
|
||||
encoding: UTF8
|
||||
state: present
|
||||
|
||||
- name: Создание таблицы
|
||||
community.postgresql.postgresql_query:
|
||||
db: "{{ postgres_db }}"
|
||||
query: |
|
||||
CREATE TABLE IF NOT EXISTS contacts (
|
||||
имя VARCHAR(100),
|
||||
телефон VARCHAR(20)
|
||||
);
|
||||
login_user: "{{ postgres_user }}"
|
||||
login_password: "{{ postgres_password }}"
|
||||
|
||||
handlers:
|
||||
- name: Перезапуск PostgreSQL
|
||||
service:
|
||||
name: postgresql
|
||||
state: restarted
|
Loading…
Reference in New Issue
Block a user