Skip to content

Commit 6bce1f9

Browse files
committed
Feat: Add postgres-01 and postgres-02
Signed-off-by: Mahdi Fooladgar (professormahi) <professormahi_f@yahoo.com>
1 parent 1b19d6f commit 6bce1f9

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

roles/postgres_hardening/tasks/hardening.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,49 @@
2121
when: not lookup('varnames', '^' + item.key + '$')
2222
with_dict: "{{ os_vars }}"
2323
tags: always
24+
25+
#################################
26+
# Check Compatibility ###########
27+
#################################
28+
- name: Print the OS
29+
debug:
30+
var: ansible_facts.os_family
31+
32+
- name: Only compatible OS versions
33+
ansible.builtin.fail:
34+
msg: "Only Ubuntu/Debian are supported"
35+
when: ansible_facts.os_family not in ["Ubuntu", "Debian"]
36+
37+
#################################
38+
# POSTGRES-01 ###################
39+
#################################
40+
- name: Check postgres service status
41+
service:
42+
name: "{{ postgres_daemon }}"
43+
state: started
44+
45+
#################################
46+
# POSTGRES-02 ###################
47+
#################################
48+
- name: Get postgres version
49+
ansible.builtin.command: psql -V
50+
register: postgres_version_raw
51+
changed_when: false
52+
check_mode: false
53+
54+
- name: Print the postgres version
55+
debug:
56+
var: postgres_version_raw
57+
58+
- name: Parse postgres-version
59+
ansible.builtin.set_fact:
60+
postgres_version: "{{ postgres_version_raw.stdout | regex_search('psql\\s\\(PostgreSQL\\)\\s(12|13|14|15|16).*', '\\1') | first }}"
61+
62+
- name: Print the postgres version
63+
debug:
64+
var: postgres_version
65+
66+
- name: Only compatible postgres versions allowed
67+
ansible.builtin.fail:
68+
msg: "Postgres Version is not secure or supported!"
69+
when: not postgres_version or 'RC' in postgres_version_raw or 'DEVEL' in postgres_version_raw or 'BETA' in postgres_version_raw

0 commit comments

Comments
 (0)