updated tags and roles
diff --git a/tasks/main.yml b/tasks/main.yml
index 41ac946..8f126db 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -13,6 +13,7 @@
 - include: cassandra.yml
 
 - include: postgres.yml
+  when: "{{ groups['pgmaster'] is defined and groups['pgstandby'] is defined }}"
 
 - name: Construct the silent-install file
   template:
diff --git a/tasks/postgres.yml b/tasks/postgres.yml
index dd2cd84..fe6690a 100644
--- a/tasks/postgres.yml
+++ b/tasks/postgres.yml
@@ -1,36 +1,48 @@
 ---
 - block:
-  - name: Obtain pgmaster IP if not provided
+  - name: Obtain pgmaster IP for DC 2, if not provided
     set_fact:
-      pgmaster_ip: "{{ hostvars[groups['dc-1-pgmaster'][0]][interface_name].ipv4.address }}"
+      pgmaster_ip: "{{ hostvars[groups['dc-2-pgmaster'][0]][interface_name].ipv4.address }}"
     when: pgmaster_ip is not defined
 
-  - name: Obtain pgstandby IP if not provided
+  - name: Obtain pgstandby IP for DC 2, if not provided
     set_fact:
-      pgstandby_ip: "{{ hostvars[groups['dc-1-pgstandby'][0]][interface_name].ipv4.address }}"
+      pgstandby_ip: "{{ hostvars[groups['dc-2-pgstandby'][0]][interface_name].ipv4.address }}"
     when: pgstandby_ip is not defined
 
+  - name: Set pgmaster_ip for DC 2, in cache, if defined
+    cache:
+      key: pgmaster_ip
+      value: '{{ pgmaster_ip }}'
+    when: pgmaster_ip is defined
+
+  - name: Set pgstandby_ip for DC 2, in cache, if defined
+    cache:
+      key: pgstandby_ip
+      value: '{{ pgstandby_ip }}'
+    when: pgstandby_ip is defined
+
   when: "{{ groups['dc-2-pgmaster'] is defined and groups['dc-2-pgstandby'] is defined and inventory_hostname in groups['dc-2'] }}"
 
 - block:
-  - name: Obtain pgmaster IP if not provided
+  - name: Obtain pgmaster IP for DC 1, if not provided
     set_fact:
       pgmaster_ip: "{{ hostvars[groups['dc-1-pgmaster'][0]][interface_name].ipv4.address }}"
-    when: pgmaster_ip is not defined
+    when: pgmaster_ip is not defined and groups['dc-1-pgmaster'] is defined
 
-  - name: Obtain pgstandby IP if not provided
+  - name: Obtain pgstandby IP for DC 1, if not provided
     set_fact:
       pgstandby_ip: "{{ hostvars[groups['dc-1-pgstandby'][0]][interface_name].ipv4.address }}"
     when: pgstandby_ip is not defined
 
+  - name: Set pgmaster_ip for DC 1, in cache, if defined
+    cache:
+      key: pgmaster_ip
+      value: '{{ pgmaster_ip }}'
+
+  - name: Set pgstandby_ip for DC 1, in cache, if defined
+    cache:
+      key: pgstandby_ip
+      value: '{{ pgstandby_ip }}'
+
   when: "{{ groups['dc-1-pgmaster'] is defined and groups['dc-1-pgstandby'] is defined and inventory_hostname in groups['dc-1'] }}"
-
-- name: Set pgmaster_ip in cache
-  cache:
-    key: pgmaster_ip
-    value: '{{ pgmaster_ip }}'
-
-- name: Set pgstandby_ip in cache
-  cache:
-    key: pgstandby_ip
-    value: '{{ pgstandby_ip }}'