Repository navigation
Expand file tree
/
Copy pathinstall_postgres.yml
More file actions
146 lines (134 loc) · 3.82 KB
/
Copy pathinstall_postgres.yml
File metadata and controls
146 lines (134 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
---
- name: Install POSTGRES
hosts: postgres_servers
vars:
postgres_version: postgresql-11.4
postgres_tarball_url: "https://ftp.postgresql.org/pub/source/v11.4/{{ postgres_version }}.tar.gz"
postgres_install_dir: "/tmp/{{ postgres_version }}"
postgres_init_dir: "/usr/local/pgsql/data/"
postgres_user: "postgres"
tasks:
- name: Install POSTGRES Depends Debian
apt:
name: "{{ item }}"
update_cache: yes
loop:
- zlib1g-dev
- build-essential
- aptitude
- libssl-dev
- python3-dev
- libreadline7
- libreadline-dev
- openssl
- sudo
when: ansible_os_family == "Debian"
- name: Install POSTGRES Depends Centos
yum:
name: "{{ item }}"
loop:
- openssl-devel
- pcre-devel
- redhat-rpm-config
- gcc
- readline-devel
- libffi-devel
- python-devel
- openssl
- sudo
when: ansible_os_family == "RedHat"
- name: install the 'Development tools' package group
yum:
name: "@Development tools"
state: present
when: ansible_os_family == "RedHat"
- name: Downloading POSTGRES sources
get_url:
url: "{{ postgres_tarball_url }}"
dest: "/tmp/{{ postgres_version }}.tar.gz"
register: postgres_source
- name: Unpacking POSTGRES
unarchive:
copy: no
dest: /tmp/
src: "/tmp/{{ postgres_version }}.tar.gz"
register: postgres_source_unpack
- name: Configuring POSTGRES source with custom modules
command: "./configure --prefix=/usr/local/ --with-openssl"
args:
chdir: "{{ postgres_install_dir }}"
# when: postgres_source_unpack is changed
register: postgres_configure
- name: Installing POSTGRES
shell: make && make install
args:
chdir: "{{ postgres_install_dir }}"
when: postgres_configure is changed
- name: Add the user 'postgres'
user:
name: "{{ postgres_user }}"
ssh_key_bits: 2048
ssh_key_file: .ssh/id_rsa
comment: Postgres User
shell: /bin/bash
- name: Set authorized key for user postgres copying it from current user
authorized_key:
user: "{{ postgres_user }}"
state: present
key: "{{ lookup('file', lookup('env','HOME') + '/.ssh/id_rsa.pub') }}"
- name: Create a directory if it does not exist
file:
path: "{{ postgres_init_dir }}"
state: directory
mode: '0755'
recurse: yes
owner: "{{ postgres_user }}"
group: "{{ postgres_user }}"
- name: Ensure PostgreSQL database is initialized.
command: "initdb -D {{ postgres_init_dir }}"
become: true
become_user: "{{ postgres_user }}"
# - /etc/ssl/crt/
# - /etc/ssl/private/
# - /etc/ssl/csr/
#
# - name: Copy configs
# copy:
# src: "{{ item.src }}"
# dest: "{{ item.dst }}"
# force: yes
# mode: 0755
# with_items:
# - { src: '/home/ansible/ansible/postgres/postgres_test.conf', dst: '/etc/postgres/postgres.conf' }
# - { src: '/home/ansible/ansible/postgres/postgres.service', dst: '/lib/systemd/system/postgres.service' }
# - { src: '/home/ansible/ansible/postgres/index.html', dst: '/sites/index.html' }
#
# - name: Delete HTTPD
# yum:
# name: [ 'httpd', 'firewalld' ]
# state: removed
# when: ansible_os_family == "RedHat"
#
## - name: Generate a Self Signed OpenSSL certificate
## openssl_certificate:
## path: /etc/ssl/crt/ansible.com.crt
## privatekey_path: /etc/ssl/private/ansible.com.pem
## csr_path: /etc/ssl/csr/ansible.com.csr
## provider: selfsigned
#
#
# - name: Starting POSTGRES
# become: yes
# service:
# name: postgres.service
# state: restarted
# enabled: yes
#
# - name: iptables flush filter
# iptables:
# chain: "{{ item }}"
# flush: yes
# loop:
# - INPUT
# - FORWARD
# - OUTPUT