Skip to content

Commit

Permalink
Merge pull request #163 from jt-edb/fix_pg_sr_cluster_nodes_4
Browse files Browse the repository at this point in the history
pg_sr_cluster_nodes improvement
  • Loading branch information
vibhorkumar123 authored Mar 2, 2021
2 parents fa4db10 + ad8c6fb commit 2ec629c
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions plugins/lookup/pg_sr_cluster_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ def run(self, terms, variables=None, **kwargs):
else:
node_private_ip = terms[0]

# If no primary found in the inventory we return an empty list
if 'primary' not in variables['groups']:
return []

# Initiate pg_clusters and pg_primary_map for each primary node we have
# in the inventory.
for host in variables['groups']['primary']:
hostvars = myvars['hostvars'][host]
private_ip = hostvars['private_ip']
Expand All @@ -70,25 +76,26 @@ def run(self, terms, variables=None, **kwargs):
)
pg_primary_map[private_ip] = private_ip

if 'standby' not in variables['groups']:
return pg_clusters[pg_primary_map[node_private_ip]]

for host in variables['groups']['standby']:
hostvars = myvars['hostvars'][host]
pg_standbys[host] = dict(
node_type='standby',
ansible_host=hostvars['ansible_host'],
hostname=hostvars.get('hostname',
hostvars.get('ansible_hostname')),
private_ip=hostvars['private_ip'],
upstream_node_private_ip=hostvars['upstream_node_private_ip'],
replication_type=hostvars.get('replication_type',
'asynchronous'),
inventory_hostname=hostvars['inventory_hostname']
)
# Populate pg_standbys dict if we have standby nodes in the inventory
if 'standby' in variables['groups']:
for host in variables['groups']['standby']:
hostvars = myvars['hostvars'][host]
pg_standbys[host] = dict(
node_type='standby',
ansible_host=hostvars['ansible_host'],
hostname=hostvars.get('hostname',
hostvars.get('ansible_hostname')),
private_ip=hostvars['private_ip'],
upstream_node_private_ip=hostvars['upstream_node_private_ip'],
replication_type=hostvars.get('replication_type',
'asynchronous'),
inventory_hostname=hostvars['inventory_hostname']
)

pg_standbys_len = len(pg_standbys.keys())

# Append the standby nodes into the right pg_clusters item, based on
# standby's upstream node.
while pg_standbys_len != 0:

for k in list(pg_standbys.keys()):
Expand Down

0 comments on commit 2ec629c

Please sign in to comment.