summaryrefslogtreecommitdiffstats
path: root/lib/ansible/vars
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-05 16:16:47 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-05 16:16:47 +0000
commit7a7fb74454bb3a169acecd30e87067502bfe3260 (patch)
treed684cbea7ffc70bd39a1e52bb65b0ea5ae156bda /lib/ansible/vars
parentAdding upstream version 2.16.6. (diff)
downloadansible-core-7a7fb74454bb3a169acecd30e87067502bfe3260.tar.xz
ansible-core-7a7fb74454bb3a169acecd30e87067502bfe3260.zip
Adding upstream version 2.17.0.upstream/2.17.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/ansible/vars')
-rw-r--r--lib/ansible/vars/clean.py4
-rw-r--r--lib/ansible/vars/fact_cache.py3
-rw-r--r--lib/ansible/vars/hostvars.py10
-rw-r--r--lib/ansible/vars/manager.py30
-rw-r--r--lib/ansible/vars/reserved.py4
5 files changed, 30 insertions, 21 deletions
diff --git a/lib/ansible/vars/clean.py b/lib/ansible/vars/clean.py
index c49e63e..559242e 100644
--- a/lib/ansible/vars/clean.py
+++ b/lib/ansible/vars/clean.py
@@ -1,9 +1,7 @@
# Copyright (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-# Make coding more python3-ish
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
import os
import re
diff --git a/lib/ansible/vars/fact_cache.py b/lib/ansible/vars/fact_cache.py
index 868a905..ce0dc3a 100644
--- a/lib/ansible/vars/fact_cache.py
+++ b/lib/ansible/vars/fact_cache.py
@@ -3,8 +3,7 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
from collections.abc import MutableMapping
diff --git a/lib/ansible/vars/hostvars.py b/lib/ansible/vars/hostvars.py
index a76811b..bb0372e 100644
--- a/lib/ansible/vars/hostvars.py
+++ b/lib/ansible/vars/hostvars.py
@@ -15,9 +15,7 @@
# 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 __future__ import annotations
from collections.abc import Mapping
@@ -93,8 +91,7 @@ class HostVars(Mapping):
return self._find_host(host_name) is not None
def __iter__(self):
- for host in self._inventory.hosts:
- yield host
+ yield from self._inventory.hosts
def __len__(self):
return len(self._inventory.hosts)
@@ -128,8 +125,7 @@ class HostVarsVars(Mapping):
return (var in self._vars)
def __iter__(self):
- for var in self._vars.keys():
- yield var
+ yield from self._vars.keys()
def __len__(self):
return len(self._vars.keys())
diff --git a/lib/ansible/vars/manager.py b/lib/ansible/vars/manager.py
index 8282190..96559a6 100644
--- a/lib/ansible/vars/manager.py
+++ b/lib/ansible/vars/manager.py
@@ -15,9 +15,7 @@
# 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 __future__ import annotations
import os
import sys
@@ -203,6 +201,7 @@ class VariableManager:
for role in play.roles:
if role.public:
all_vars = _combine_and_track(all_vars, role.get_default_vars(), "role '%s' defaults" % role.name)
+
if task:
# set basedirs
if C.PLAYBOOK_VARS_ROOT == 'all': # should be default
@@ -353,8 +352,8 @@ class VariableManager:
)
try:
play_search_stack = play.get_search_path()
- found_file = real_file = self._loader.path_dwim_relative_stack(play_search_stack, 'vars', vars_file)
- data = preprocess_vars(self._loader.load_from_file(found_file, unsafe=True, cache=False))
+ found_file = self._loader.path_dwim_relative_stack(play_search_stack, 'vars', vars_file)
+ data = preprocess_vars(self._loader.load_from_file(found_file, unsafe=True, cache='vaulted'))
if data is not None:
for item in data:
all_vars = _combine_and_track(all_vars, item, "play vars_files from '%s'" % vars_file)
@@ -515,7 +514,7 @@ class VariableManager:
return variables
def get_delegated_vars_and_hostname(self, templar, task, variables):
- """Get the delegated_vars for an individual task invocation, which may be be in the context
+ """Get the delegated_vars for an individual task invocation, which may be in the context
of an individual loop iteration.
Not used directly be VariableManager, but used primarily within TaskExecutor
@@ -791,3 +790,22 @@ class VarsWithSources(MutableMapping):
def copy(self):
return VarsWithSources.new_vars_with_sources(self.data.copy(), self.sources.copy())
+
+ def __or__(self, other):
+ if isinstance(other, MutableMapping):
+ c = self.data.copy()
+ c.update(other)
+ return c
+ return NotImplemented
+
+ def __ror__(self, other):
+ if isinstance(other, MutableMapping):
+ c = self.__class__()
+ c.update(other)
+ c.update(self.data)
+ return c
+ return NotImplemented
+
+ def __ior__(self, other):
+ self.data.update(other)
+ return self.data
diff --git a/lib/ansible/vars/reserved.py b/lib/ansible/vars/reserved.py
index 2d1b4d5..aece04d 100644
--- a/lib/ansible/vars/reserved.py
+++ b/lib/ansible/vars/reserved.py
@@ -15,9 +15,7 @@
# 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 __future__ import annotations
from ansible.playbook import Play
from ansible.playbook.block import Block