Skip to content

Instantly share code, notes, and snippets.

View mkrizek's full-sized avatar

Martin Krizek mkrizek

View GitHub Profile
diff --git a/lib/ansible/executor/play_iterator.py b/lib/ansible/executor/play_iterator.py
index 51799cc7a4e..c9712500249 100644
--- a/lib/ansible/executor/play_iterator.py
+++ b/lib/ansible/executor/play_iterator.py
@@ -21,7 +21,6 @@ __metaclass__ = type
import fnmatch
-from collections import deque
from enum import IntEnum, IntFlag
terraform {
required_providers {
{{ tf_provider['name'] }} = {
source = "{{ tf_provider['source'] }}"
version = "{{ tf_provider['version'] }}"
}
}
}
@mkrizek
mkrizek / ansible-jinja-types.md
Last active June 7, 2024 11:59
Ansible, Jinja2 and Types

Ansible, Jinja2 and Types

Strings, strings everywhere

Jinja2 is a templating engine and as such its primary use case is to render templates into text; which is usually HTML output saved into text file.

Consider the following Ansible play that uses Jinja2 templates to evaluate expressions:

- hosts: localhost
  gather_facts: no
diff --git a/migrate.py b/migrate.py
index 014b90c..fed8256 100755
--- a/migrate.py
+++ b/migrate.py
@@ -119,7 +119,7 @@ REWRITE_CLASS_PROPERTY_PLUGINS= {
VARDIR = os.environ.get('GRAVITY_VAR_DIR', '.cache')
LOGFILE = os.path.join(VARDIR, 'errors.log')
-REMOVE = set()
+REMOVE = defaultdict(lambda: defaultdict(set))
@mkrizek
mkrizek / diff.diff
Last active December 4, 2019 14:58
65365
commit 960e971b01a8493d40245a9cdb018b4d1ad13c33 (HEAD -> issue-65365)
Author: Martin Krizek <[email protected]>
Date: Wed Dec 4 15:55:52 2019 +0100
Set HostVars._variable_manager's attrs
When HostVars are part of the data that goes through (de)serialization
when being passed from a worker process to the main process, its
variable manager reference loses some of its attributes due to the
implementation of __getstate__ and __setstate__ (perf utilization).
diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py
index 5782c93c83..b887f6c8a8 100644
--- a/lib/ansible/executor/task_executor.py
+++ b/lib/ansible/executor/task_executor.py
@@ -420,6 +420,7 @@ class TaskExecutor:
}
if self._connection.become:
clear_plugins['become'] = self._connection.become._load_name
+ self._connection.become.prompt = ''
diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py
index cd4050d8db..ee2cca5695 100644
--- a/lib/ansible/plugins/strategy/__init__.py
+++ b/lib/ansible/plugins/strategy/__init__.py
@@ -875,15 +875,23 @@ class StrategyBase:
host_results = []
for host in notified_hosts:
if not iterator.is_failed(host) or play_context.force_handlers:
- task_vars = self._variable_manager.get_vars(play=iterator._play, host=host, task=handler)
- self.add_tqm_variables(task_vars, play=iterator._play)
diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py
index 41b74edabd..98466cb37c 100644
--- a/lib/ansible/plugins/strategy/__init__.py
+++ b/lib/ansible/plugins/strategy/__init__.py
@@ -368,7 +368,7 @@ class StrategyBase:
return self._inventory.get_host(host_name)
def search_handler_blocks_by_name(handler_name, handler_blocks):
- for handler_block in handler_blocks:
+ for handler_block in reversed(handler_blocks):
diff --git a/lib/ansible/executor/task_queue_manager.py b/lib/ansible/executor/task_queue_manager.py
index 67a741b989..844ab621a8 100644
--- a/lib/ansible/executor/task_queue_manager.py
+++ b/lib/ansible/executor/task_queue_manager.py
@@ -232,7 +232,7 @@ class TaskQueueManager:
new_play = play.copy()
new_play.post_validate(templar)
- new_play.handlers = new_play.compile_roles_handlers() + new_play.handlers
+ new_play.handlers = new_play.handlers + new_play.compile_roles_handlers()
@mkrizek
mkrizek / jinja-native.yaml
Created June 1, 2018 12:52
Native Jinja2 Types
# Upstream Jinja2 native types docs: http://jinja.pocoo.org/docs/2.10/nativetypes/
# Upstream Jinja2 native types PR: https://github.com/pallets/jinja/pull/708
# Jinja2 native types in Ansible PR: https://github.com/ansible/ansible/pull/32738
# ansible-devel@ announcement: https://groups.google.com/forum/#!topic/ansible-devel/o42OoC0VZ4A
# Preserving types of castings
- hosts: localhost
gather_facts: no
vars:
adict: