Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

# (c) 2017 Ansible By Red Hat 

# 

# This file is part of Ansible 

# 

# Ansible is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# Ansible is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the GNU General Public License 

# along with Ansible. If not, see <http://www.gnu.org/licenses/>. 

 

# Make coding more python3-ish 

from __future__ import (absolute_import, division, print_function) 

__metaclass__ = type 

 

from ansible.playbook import Play 

from ansible.playbook.block import Block 

from ansible.playbook.role import Role 

from ansible.playbook.task import Task 

 

try: 

from __main__ import display 

except ImportError: 

from ansible.utils.display import Display 

display = Display() 

 

 

def get_reserved_names(include_private=True): 

''' this function returns the list of reserved names associated with play objects''' 

 

public = set() 

private = set() 

result = set() 

 

# FIXME: find a way to 'not hardcode', possibly need role deps/includes 

class_list = [Play, Role, Block, Task] 

 

for aclass in class_list: 

aobj = aclass() 

 

# build ordered list to loop over and dict with attributes 

for attribute in aobj.__dict__['_attributes']: 

49 ↛ 50line 49 didn't jump to line 50, because the condition on line 49 was never true if 'private' in attribute: 

private.add(attribute) 

else: 

public.add(attribute) 

 

# local_action is implicit with action 

55 ↛ 60line 55 didn't jump to line 60, because the condition on line 55 was never false if 'action' in public: 

public.add('local_action') 

 

# loop implies with_ 

# FIXME: remove after with_ is not only deprecated but removed 

60 ↛ 63line 60 didn't jump to line 63, because the condition on line 60 was never false if 'loop' in private or 'loop' in public: 

public.add('with_') 

 

63 ↛ 66line 63 didn't jump to line 66, because the condition on line 63 was never false if include_private: 

result = public.union(private) 

else: 

result = public 

 

return result 

 

 

def warn_if_reserved(myvars): 

''' this function warns if any variable passed conflicts with internally reserved names ''' 

 

varnames = set(myvars) 

varnames.discard('vars') # we add this one internally, so safe to ignore 

76 ↛ 77line 76 didn't jump to line 77, because the loop on line 76 never started for varname in varnames.intersection(_RESERVED_NAMES): 

display.warning('Found variable using reserved name: %s' % varname) 

 

 

_RESERVED_NAMES = frozenset(get_reserved_names())