Evaluate only_if in group_by

parent 93fe43f0
...@@ -20,7 +20,7 @@ import ansible ...@@ -20,7 +20,7 @@ import ansible
from ansible.callbacks import vv from ansible.callbacks import vv
from ansible.errors import AnsibleError as ae from ansible.errors import AnsibleError as ae
from ansible.runner.return_data import ReturnData from ansible.runner.return_data import ReturnData
from ansible.utils import parse_kv, template from ansible.utils import parse_kv, template, check_conditional
class ActionModule(object): class ActionModule(object):
''' Create inventory groups based on variables ''' ''' Create inventory groups based on variables '''
...@@ -46,6 +46,8 @@ class ActionModule(object): ...@@ -46,6 +46,8 @@ class ActionModule(object):
groups = {} groups = {}
for host in self.runner.host_set: for host in self.runner.host_set:
data = inject['hostvars'][host] data = inject['hostvars'][host]
if not check_conditional(template(self.runner.basedir, self.runner.conditional, data)):
continue
group_name = template(self.runner.basedir, args['key'], data) group_name = template(self.runner.basedir, args['key'], data)
group_name = group_name.replace(' ','-') group_name = group_name.replace(' ','-')
if group_name not in groups: if group_name not in groups:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment