Skip to content

Commit

Permalink
Merge pull request ANXS#299 from jlozadad/jlozadad_handlers
Browse files Browse the repository at this point in the history
added the use of handlers
  • Loading branch information
Jonathan Lozada D committed Mar 29, 2018
2 parents 28a6e9c + 960832a commit 7b75bec
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 44 deletions.
17 changes: 13 additions & 4 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# file: postgresql/handlers/main.yml

- name: restart postgresql
service:
name: "{{ postgresql_service_name }}"
state: restarted
- name: restart postgresql with service
service:
name: "{{ postgresql_service_name }}"
state: restarted
enabled: yes

- name: restart postgresql with systemd
systemd:
name: "{{ postgresql_service_name }}"
state: restarted
enabled: yes
when: ansible_service_mgr == 'systemd'

13 changes: 2 additions & 11 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
state: directory
mode: 0755
when: ansible_os_family == "RedHat"
notify: restart postgresql with systemd

- name: PostgreSQL | Use the conf directory when starting the Postgres service | RedHat
template:
Expand All @@ -151,15 +152,5 @@
owner: "{{ postgresql_service_user }}"
group: "{{ postgresql_service_group }}"
mode: u=rwX,g=rwXs,o=rx
notify: restart postgresql with service

- name: PostgreSQL | Enable service
service:
name: "{{ postgresql_service_name }}"
enabled: yes
when: postgresql_service_enabled

- name: PostgreSQL | Restart PostgreSQL
service:
name: "{{ postgresql_service_name }}"
state: restarted
when: postgresql_configuration_pt1.changed or postgresql_configuration_pt2.changed or postgresql_configuration_pt3.changed or postgresql_systemd_custom_conf.changed
61 changes: 32 additions & 29 deletions tasks/install_yum.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,39 @@

# The standard ca-certs are needed because without them apt_key will fail to
# validate www.postgresql.org (or probably any other source).
- name: PostgreSQL | Make sure the CA certificates are available
yum:
name: ca-certificates
state: present

- name: PostgreSQL | Add PostgreSQL repository
yum:
name: "{{ postgresql_yum_repository_url }}"
state: present
- block:
- name: PostgreSQL | Make sure the CA certificates are available
yum:
name: ca-certificates
state: present

- name: PostgreSQL | Make sure the dependencies are installed
yum:
name: "{{ item }}"
state: present
update_cache: yes
with_items: ["python-psycopg2", "python-pycurl", "glibc-common"]
- name: PostgreSQL | Add PostgreSQL repository
yum:
name: "{{ postgresql_yum_repository_url }}"
state: present

- name: PostgreSQL | Install PostgreSQL
yum:
name: "{{ item }}"
state: present
environment: "{{ postgresql_env }}"
with_items:
- "postgresql{{ postgresql_version_terse }}-server"
- "postgresql{{ postgresql_version_terse }}"
- "postgresql{{ postgresql_version_terse }}-contrib"
- name: PostgreSQL | Make sure the dependencies are installed
yum:
name: "{{ item }}"
state: present
update_cache: yes
with_items: ["python-psycopg2", "python-pycurl", "glibc-common"]

- name: PostgreSQL | Install PostgreSQL
yum:
name: "{{ item }}"
state: present
environment: "{{ postgresql_env }}"
with_items:
- "postgresql{{ postgresql_version_terse }}-server"
- "postgresql{{ postgresql_version_terse }}"
- "postgresql{{ postgresql_version_terse }}-contrib"

- name: PostgreSQL | PGTune
yum:
name: pgtune
state: present
environment: "{{ postgresql_env }}"
when: postgresql_pgtune

- name: PostgreSQL | PGTune
yum:
name: pgtune
state: present
environment: "{{ postgresql_env }}"
when: postgresql_pgtune

3 comments on commit 7b75bec

@gclough
Copy link
Owner

@gclough gclough commented on 7b75bec Mar 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jlozadad ... I'm trying to understand this update, and I can only find two places where the "restart postgresql with [service|systemd]" is notified.

 PostgreSQL | Ensure the systemd directory for PostgreSQL exists | RedHat
  file:
    name: "/etc/systemd/system/postgresql-{{ postgresql_version }}.service.d"
    state: directory
    mode: 0755
  when: ansible_os_family == "RedHat"
  notify: restart postgresql with systemd

From my reading, that means that on RedHat it will always use systemd... but that's only useful on RedHat v7. AFAIK RedHat v6 uses "service".

and

- name: PostgreSQL | Ensure the pid directory for PostgreSQL exists
  file:
    name: "{{ postgresql_pid_directory }}"
    state: directory
    owner: "{{ postgresql_service_user }}"
    group: "{{ postgresql_service_group }}"
    mode: u=rwX,g=rwXs,o=rx
  notify: restart postgresql with service

That will trigger the service restart on all system types, not just those that use systemd, right? Do I have my wires crossed?

I made some fairly wholesale changes in ANXS#294, so that clusters will reload when possible, and will only restart when absolutely necessary. I'll try to merge your updates into that, but I wanted to make sure that I was understanding things correctly.

@aoyawale
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it supposed to restart on both. The only change I did was add for systemd and it only does for systemd due to when: ansible_service_mgr == 'systemd

@gclough
Copy link
Owner

@gclough gclough commented on 7b75bec Apr 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jlozadad, it seems that the extensions/*.yml files still use the register: restart postgresql syntax. I've updated that as a part of ANXS#310, but I could do a separate PR for that if you think it's necessary to split it out.

Please sign in to comment.