mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 05:42:50 +00:00
Replace .iteritems() with six.iteritems()
Replace .iteritems() with six.iteritems() everywhere except in module_utils (because there's no 'six' on the remote host). And except in lib/ansible/galaxy/data/metadata_template.j2, because I'm not sure six is available there.
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from six import iteritems
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.plugins.action import ActionBase
|
||||
@@ -32,7 +33,7 @@ class ActionModule(ActionBase):
|
||||
def run(self, tmp=None, task_vars=dict()):
|
||||
facts = dict()
|
||||
if self._task.args:
|
||||
for (k, v) in self._task.args.iteritems():
|
||||
for (k, v) in iteritems(self._task.args):
|
||||
k = self._templar.template(k)
|
||||
|
||||
if not isidentifier(k):
|
||||
|
||||
2
lib/ansible/plugins/cache/__init__.py
vendored
2
lib/ansible/plugins/cache/__init__.py
vendored
@@ -60,7 +60,7 @@ class FactCache(MutableMapping):
|
||||
|
||||
def copy(self):
|
||||
""" Return a primitive copy of the keys and values from the cache. """
|
||||
return dict([(k, v) for (k, v) in self.iteritems()])
|
||||
return dict([(k, v) for (k, v) in iteritems(self)])
|
||||
|
||||
def keys(self):
|
||||
return self._plugin.keys()
|
||||
|
||||
@@ -39,6 +39,8 @@ import sys
|
||||
from termios import tcflush, TCIFLUSH
|
||||
from binascii import hexlify
|
||||
|
||||
from six import iteritems
|
||||
|
||||
from ansible import constants as C
|
||||
from ansible.errors import AnsibleError, AnsibleConnectionFailure, AnsibleFileNotFound
|
||||
from ansible.plugins.connections import ConnectionBase
|
||||
@@ -306,8 +308,8 @@ class Connection(ConnectionBase):
|
||||
def _any_keys_added(self):
|
||||
|
||||
added_any = False
|
||||
for hostname, keys in self.ssh._host_keys.iteritems():
|
||||
for keytype, key in keys.iteritems():
|
||||
for hostname, keys in iteritems(self.ssh._host_keys):
|
||||
for keytype, key in iteritems(keys):
|
||||
added_this_time = getattr(key, '_added_by_ansible_this_time', False)
|
||||
if added_this_time:
|
||||
return True
|
||||
@@ -327,18 +329,18 @@ class Connection(ConnectionBase):
|
||||
|
||||
f = open(filename, 'w')
|
||||
|
||||
for hostname, keys in self.ssh._host_keys.iteritems():
|
||||
for hostname, keys in iteritems(self.ssh._host_keys):
|
||||
|
||||
for keytype, key in keys.iteritems():
|
||||
for keytype, key in iteritems(keys):
|
||||
|
||||
# was f.write
|
||||
added_this_time = getattr(key, '_added_by_ansible_this_time', False)
|
||||
if not added_this_time:
|
||||
f.write("%s %s %s\n" % (hostname, keytype, key.get_base64()))
|
||||
|
||||
for hostname, keys in self.ssh._host_keys.iteritems():
|
||||
for hostname, keys in iteritems(self.ssh._host_keys):
|
||||
|
||||
for keytype, key in keys.iteritems():
|
||||
for keytype, key in iteritems(keys):
|
||||
added_this_time = getattr(key, '_added_by_ansible_this_time', False)
|
||||
if added_this_time:
|
||||
f.write("%s %s %s\n" % (hostname, keytype, key.get_base64()))
|
||||
|
||||
@@ -38,6 +38,7 @@ import uuid
|
||||
import yaml
|
||||
from jinja2.filters import environmentfilter
|
||||
from distutils.version import LooseVersion, StrictVersion
|
||||
from six import iteritems
|
||||
|
||||
from ansible import errors
|
||||
from ansible.parsing.yaml.dumper import AnsibleDumper
|
||||
@@ -245,7 +246,7 @@ def combine(*terms, **kwargs):
|
||||
if recursive:
|
||||
return reduce(merge_hash, terms)
|
||||
else:
|
||||
return dict(itertools.chain(*map(dict.iteritems, terms)))
|
||||
return dict(itertools.chain(*map(iteritems, terms)))
|
||||
|
||||
class FilterModule(object):
|
||||
''' Ansible core jinja2 filters '''
|
||||
|
||||
@@ -20,6 +20,8 @@ from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from six.moves import queue as Queue
|
||||
from six import iteritems
|
||||
|
||||
import time
|
||||
|
||||
from ansible import constants as C
|
||||
@@ -207,7 +209,7 @@ class StrategyBase:
|
||||
if task_result._task._role is not None and result[0] in ('host_task_ok', 'host_task_failed'):
|
||||
# lookup the role in the ROLE_CACHE to make sure we're dealing
|
||||
# with the correct object and mark it as executed
|
||||
for (entry, role_obj) in iterator._play.ROLE_CACHE[task_result._task._role._role_name].iteritems():
|
||||
for (entry, role_obj) in iteritems(iterator._play.ROLE_CACHE[task_result._task._role._role_name]):
|
||||
if role_obj._uuid == task_result._task._role._uuid:
|
||||
role_obj._had_task_run[host.name] = True
|
||||
|
||||
@@ -358,7 +360,7 @@ class StrategyBase:
|
||||
groups[group_name] = []
|
||||
groups[group_name].append(host)
|
||||
|
||||
for group_name, hosts in groups.iteritems():
|
||||
for group_name, hosts in iteritems(groups):
|
||||
new_group = self._inventory.get_group(group_name)
|
||||
if not new_group:
|
||||
# create the new group and add it to inventory
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from six import iteritems
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.executor.play_iterator import PlayIterator
|
||||
from ansible.playbook.block import Block
|
||||
@@ -63,7 +65,7 @@ class StrategyModule(StrategyBase):
|
||||
lowest_cur_block = len(iterator._blocks)
|
||||
|
||||
display.debug("counting tasks in each state of execution")
|
||||
for (k, v) in host_tasks.iteritems():
|
||||
for (k, v) in iteritems(host_tasks):
|
||||
if v is None:
|
||||
continue
|
||||
|
||||
|
||||
Reference in New Issue
Block a user