tnt4brain

Ansible staticaly tagged play support

Nov 6th, 2022
1,586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.22 KB | Source Code | 0 0
  1. --- block.py    2022-11-05 22:36:42.946474359 +0300
  2. +++ block.py    2022-11-05 23:34:29.554474359 +0300
  3. @@ -376,8 +376,8 @@
  4.                      if filtered_block.has_tasks():
  5.                          tmp_list.append(filtered_block)
  6.                  elif (task.action in C._ACTION_META or
  7. -                        (task.action in C._ACTION_INCLUDE and task.evaluate_tags([], self._play.skip_tags, all_vars=all_vars)) or
  8. -                        task.evaluate_tags(self._play.only_tags, self._play.skip_tags, all_vars=all_vars)):
  9. +                        (task.action in C._ACTION_INCLUDE and task.evaluate_tags([], self._play.skip_tags, all_vars=all_vars, set_tags=self._play.set_tags, unset_tags=self._play.unset_tags)) or
  10. +                        task.evaluate_tags(self._play.only_tags, self._play.skip_tags, all_vars=all_vars, set_tags=self._play.set_tags, unset_tags=self._play.unset_tags)):
  11.                      tmp_list.append(task)
  12.              return tmp_list
  13.  
  14. --- taggable.py 2022-11-05 22:34:58.022474359 +0300
  15. +++ taggable.py 2022-11-05 23:25:42.634474359 +0300
  16. @@ -30,6 +30,10 @@
  17.      untagged = frozenset(['untagged'])
  18.      _tags = FieldAttribute(isa='list', default=list, listof=(string_types, int), extend=True)
  19.  
  20. +    # Tags mechanism
  21. +    _set_tags = FieldAttribute(isa='list', default=list, listof=(string_types, int), extend=True)
  22. +    _unset_tags = FieldAttribute(isa='list', default=list, listof=(string_types, int), extend=True)
  23. +
  24.      def _load_tags(self, attr, ds):
  25.          if isinstance(ds, list):
  26.              return ds
  27. @@ -42,7 +46,7 @@
  28.          else:
  29.              raise AnsibleError('tags must be specified as a list', obj=ds)
  30.  
  31. -    def evaluate_tags(self, only_tags, skip_tags, all_vars):
  32. +    def evaluate_tags(self, only_tags, skip_tags, all_vars, set_tags=frozenset(), unset_tags=frozenset()):
  33.          ''' this checks if the current item should be executed depending on tag options '''
  34.  
  35.          if self.tags:
  36. @@ -63,6 +67,10 @@
  37.  
  38.          should_run = True  # default, tasks to run
  39.  
  40. +        # Houston, process the static!
  41. +        only_tags.update(set_tags)
  42. +        skip_tags.update(unset_tags)
  43. +
  44.          if only_tags:
  45.              if 'always' in tags:
  46.                  should_run = True
  47.  
  48.  
Tags: ansible
Advertisement
Add Comment
Please, Sign In to add comment