diff options
author | Scott Dodson <sdodson@redhat.com> | 2017-02-27 12:53:09 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-27 12:53:09 -0500 |
commit | 833eb4ccfed255004ba21b51bab3c022201bbc83 (patch) | |
tree | 6cd94c1ff4184d41752e05f3b2d7d31e723716f3 | |
parent | 29b5e97870bf3c24a433b906ea56c8a21b392e0a (diff) | |
parent | 3b877826bc214c7e1e952b1968f933c40e477f50 (diff) | |
download | openshift-833eb4ccfed255004ba21b51bab3c022201bbc83.tar.gz openshift-833eb4ccfed255004ba21b51bab3c022201bbc83.tar.bz2 openshift-833eb4ccfed255004ba21b51bab3c022201bbc83.tar.xz openshift-833eb4ccfed255004ba21b51bab3c022201bbc83.zip |
Merge pull request #3503 from kwoodson/openshift_hosted_replicas
Moving replica logic to filter_plugin to fix skipped task variable behavior.
-rw-r--r-- | roles/openshift_hosted/filter_plugins/filters.py | 35 | ||||
-rw-r--r-- | roles/openshift_hosted/tasks/router/router.yml | 2 |
2 files changed, 36 insertions, 1 deletions
diff --git a/roles/openshift_hosted/filter_plugins/filters.py b/roles/openshift_hosted/filter_plugins/filters.py new file mode 100644 index 000000000..cbfadfe9d --- /dev/null +++ b/roles/openshift_hosted/filter_plugins/filters.py @@ -0,0 +1,35 @@ +#!/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} diff --git a/roles/openshift_hosted/tasks/router/router.yml b/roles/openshift_hosted/tasks/router/router.yml index 3535d5f5e..607ace7f9 100644 --- a/roles/openshift_hosted/tasks/router/router.yml +++ b/roles/openshift_hosted/tasks/router/router.yml @@ -10,7 +10,7 @@ - name: set_fact replicas set_fact: - replicas: "{{ openshift.hosted.router.replicas | default(router_nodes.results.results[0]['items'] | length) }}" + replicas: "{{ openshift.hosted.router.replicas|default(None) | get_router_replicas(router_nodes) }}" - block: |