Host Variables Validation in Ansible

# action plugin for Ansible 2.x
from ansible.plugins.action import ActionBase
class ActionModule(ActionBase): def run(self, tmp=None, task_vars=None):
if task_vars is None:
task_vars = dict()
result = super(ActionModule, self).run(tmp, task_vars)
result['changed'] = False
result['failed'] = False
# put validation code here... you can for example use
# all this host variables in task_vars, and for example
# compare with task_vars['hostvars'], which contains all
# variables of all hosts
# if something is wrong, raise an error as follows:
# result['failed'] = True
# result['msg'] = 'Duplicate IP found: ...'
return result
- name: validate xxx configuration
action: validate_xxx



Cloud infrastructure enthousiast, open source developer, technical solution engineer at Google

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store