#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Custom filters for use in openshift_hosted
'''


class FilterModule(object):
    ''' Custom ansible filters for use by openshift_hosted role'''

    @staticmethod
    def get_router_replicas(replicas=None, router_nodes=None):
        ''' This function will return the number of replicas
            based on the results from the defined
            openshift.hosted.router.replicas OR
            the query from oc_obj on openshift nodes with a selector OR
            default to 1

        '''
        # We always use what they've specified if they've specified a value
        if replicas is not None:
            return replicas

        if (isinstance(router_nodes, dict) and
                'results' in router_nodes and
                'results' in router_nodes['results'] and
                'items' in router_nodes['results']['results']):

            return len(router_nodes['results']['results'][0]['items'])

        return 1

    def filters(self):
        ''' returns a mapping of filters to methods '''
        return {'get_router_replicas': self.get_router_replicas}

@@ -672,16 +672,141 @@
 plicas%0A%0A
+        replicas = 1%0A%0A        # Ignore boolean expression limit of 5.%0A        # pylint: disable=too-many-boolean-expressions%0A
         
@@ -943,24 +943,161 @@
 sults'%5D and%0A
+                isinstance(router_nodes%5B'results'%5D%5B'results'%5D, list) and%0A                len(router_nodes%5B'results'%5D%5B'results'%5D) %3E 0 and%0A
             
@@ -1145,16 +1145,19 @@
 esults'%5D
+%5B0%5D
 ):%0A%0A    
@@ -1164,22 +1164,102 @@
         
-return
+if len(router_nodes%5B'results'%5D%5B'results'%5D%5B0%5D%5B'items'%5D) %3E 0:%0A                replicas =
  len(rou
@@ -1319,17 +1319,24 @@
  return 
-1
+replicas
 %0A%0A    de

Fix get_router_replicas infrastructure node count.