updated vhost_alias logic
diff --git a/tasks/main.yml b/tasks/main.yml
index 878fcfc..72ab339 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -27,6 +27,40 @@
     state: absent
   when: provided_onboarding_config_file_path is not defined
 
+- name: Initialize RMP addresses
+  set_facts:
+    vhost_alias: ''
+
+- block:
+  - name: Set vhost_alias to load_balancer
+    cache:
+      key: "vhost_alias"
+      value: "{{ load_balancer }}"
+  when: load_balancer is defined and load_balancer | trim | length > 0
+
+- block:
+  - name: Collect DC 1 RMP addresses
+    cache:
+      key: "vhost_alias"
+      value: "{{ vhost_alias }} {{ hostvars[item].private_address }}"
+    with_items: "{{ groups['dc-1-rmp'] }}"
+    when: groups['dc-1'] is defined and inventory_hostname in groups['dc-1']
+
+  - name: Collect DC 2 RMP addresses
+    cache:
+      key: "vhost_alias"
+      value: "{{ vhost_alias }} {{ hostvars[item].private_address }}"
+    with_items: "{{ groups['dc-2-rmp'] }}"
+    when: groups['dc-2'] is defined and inventory_hostname in groups['dc-2']
+
+  - name: Collect DC 3 RMP addresses
+    cache:
+      key: "vhost_alias"
+      value: "{{ vhost_alias }} {{ hostvars[item].private_address }}"
+    with_items: "{{ groups['dc-3-rmp'] }}"
+    when: groups['dc-3'] is defined and inventory_hostname in groups['dc-3']
+  when: load_balancer is not defined or load_balancer | trim | length == 0
+
 - name: Prepare onboarding config file
   template:
     src: 'apigee-provision.conf.j2'
diff --git a/templates/apigee-provision.conf.j2 b/templates/apigee-provision.conf.j2
index 7854d3c..86ca8bf 100644
--- a/templates/apigee-provision.conf.j2
+++ b/templates/apigee-provision.conf.j2
@@ -38,17 +38,7 @@
 VHOST_NAME={{ virtual_host_name }}
 
 # If you have a DNS entry for the virtual host.
-{% if load_balancer is defined and load_balancer | trim | length > 0 %}
 VHOST_ALIAS="{{ vhost_alias }}"
-{% else %}
-{% if groups['dc-3'] is defined and inventory_hostname in groups['dc-3'] %}
-VHOST_ALIAS="{{ groups['dc-3-rmp'] | join(' ') }}"
-{% elif groups['dc-2'] is defined and inventory_hostname in groups['dc-2'] %}
-VHOST_ALIAS="{{ groups['dc-2-rmp'] | join(' ') }}"
-{% else %}
-VHOST_ALIAS="{{ groups['dc-1-rmp'] | join(' ') }}"
-{% endif %}
-{% endif %}
 
 # If you do not have a DNS entry for the virtual host,
 # specify the IP and port of each router as a space-separated list: