Debian Codegraph @

lib/ansible/playbook/conditional.py

raw
1 # (c) 2012-2014, Michael DeHaan <[email protected]>
2 #
3 # This file is part of Ansible
4 #
5 # Ansible is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Ansible is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
17
18 from __future__ import annotations
19
20 from ansible.playbook.attribute import FieldAttribute
21 from ansible.utils.display import Display
22
23 display = Display()
24
25
26 class Conditional:
27 """
28 This is a mix-in class, to be used with Base to allow the object
29 to be run conditionally when a condition is met or skipped.
30 """
31
32 when = FieldAttribute(isa='list', default=list, extend=True, prepend=True)
33
34 def __init__(self, *args, **kwargs):
35 super().__init__()
36
37 def _validate_when(self, attr, name, value):
38 if not isinstance(value, list):
39 setattr(self, name, [value])