mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-30 04:49:09 -07:00
Python 2.6 str.format()
compatibility fixes.
This commit is contained in:
parent
95ff8f1a90
commit
797664d9cb
20 changed files with 43 additions and 62 deletions
|
@ -36,7 +36,7 @@ class CallbackModule(CallbackBase):
|
|||
self.play = None
|
||||
|
||||
def v2_on_any(self, *args, **kwargs):
|
||||
self._display.display("--- play: {} task: {} ---".format(getattr(self.play, 'name', None), self.task))
|
||||
self._display.display("--- play: {0} task: {1} ---".format(getattr(self.play, 'name', None), self.task))
|
||||
|
||||
self._display.display(" --- ARGS ")
|
||||
for i, a in enumerate(args):
|
||||
|
|
|
@ -141,7 +141,7 @@ class CallbackModule(CallbackBase):
|
|||
response = open_url(url, data=data, headers=headers, method='POST')
|
||||
return response.read()
|
||||
except Exception as ex:
|
||||
self._display.warning('Could not submit message to hipchat: {}'.format(ex))
|
||||
self._display.warning('Could not submit message to hipchat: {0}'.format(ex))
|
||||
|
||||
def send_msg_v1(self, msg, msg_format='text', color='yellow', notify=False):
|
||||
"""Method for sending a message to HipChat"""
|
||||
|
@ -159,7 +159,7 @@ class CallbackModule(CallbackBase):
|
|||
response = open_url(url, data=urlencode(params))
|
||||
return response.read()
|
||||
except Exception as ex:
|
||||
self._display.warning('Could not submit message to hipchat: {}'.format(ex))
|
||||
self._display.warning('Could not submit message to hipchat: {0}'.format(ex))
|
||||
|
||||
def v2_playbook_on_play_start(self, play):
|
||||
"""Display Playbook and play start messages"""
|
||||
|
|
|
@ -282,7 +282,7 @@ class CallbackModule(CallbackBase):
|
|||
|
||||
def emit(self, record):
|
||||
msg = record.rstrip('\n')
|
||||
msg = "{} {}".format(self.token, msg)
|
||||
msg = "{0} {1}".format(self.token, msg)
|
||||
self._appender.put(msg)
|
||||
self._display.vvvv("Sent event to logentries")
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ def colorize(msg, color):
|
|||
if DONT_COLORIZE:
|
||||
return msg
|
||||
else:
|
||||
return '{}{}{}'.format(COLORS[color], msg, COLORS['endc'])
|
||||
return '{0}{1}{2}'.format(COLORS[color], msg, COLORS['endc'])
|
||||
|
||||
|
||||
class CallbackModule(CallbackBase):
|
||||
|
@ -104,15 +104,15 @@ class CallbackModule(CallbackBase):
|
|||
line_length = 120
|
||||
if self.last_skipped:
|
||||
print()
|
||||
msg = colorize("# {} {}".format(task_name,
|
||||
'*' * (line_length - len(task_name))), 'bold')
|
||||
msg = colorize("# {0} {1}".format(task_name,
|
||||
'*' * (line_length - len(task_name))), 'bold')
|
||||
print(msg)
|
||||
|
||||
def _indent_text(self, text, indent_level):
|
||||
lines = text.splitlines()
|
||||
result_lines = []
|
||||
for l in lines:
|
||||
result_lines.append("{}{}".format(' ' * indent_level, l))
|
||||
result_lines.append("{0}{1}".format(' ' * indent_level, l))
|
||||
return '\n'.join(result_lines)
|
||||
|
||||
def _print_diff(self, diff, indent_level):
|
||||
|
|
|
@ -55,7 +55,7 @@ class Connection(Jail):
|
|||
|
||||
jail_uuid = self.get_jail_uuid()
|
||||
|
||||
kwargs[Jail.modified_jailname_key] = 'ioc-{}'.format(jail_uuid)
|
||||
kwargs[Jail.modified_jailname_key] = 'ioc-{0}'.format(jail_uuid)
|
||||
|
||||
display.vvv(u"Jail {iocjail} has been translated to {rawjail}".format(
|
||||
iocjail=self.ioc_jail, rawjail=kwargs[Jail.modified_jailname_key]),
|
||||
|
@ -74,6 +74,6 @@ class Connection(Jail):
|
|||
p.wait()
|
||||
|
||||
if p.returncode != 0:
|
||||
raise AnsibleError(u"iocage returned an error: {}".format(stdout))
|
||||
raise AnsibleError(u"iocage returned an error: {0}".format(stdout))
|
||||
|
||||
return stdout.strip('\n')
|
||||
|
|
|
@ -75,7 +75,7 @@ class LookupModule(LookupBase):
|
|||
setattr(self, arg, parsed)
|
||||
except ValueError:
|
||||
raise AnsibleError(
|
||||
"can't parse arg {}={} as string".format(arg, arg_raw)
|
||||
"can't parse arg {0}={1} as string".format(arg, arg_raw)
|
||||
)
|
||||
if args:
|
||||
raise AnsibleError(
|
||||
|
|
|
@ -72,7 +72,7 @@ class Hiera(object):
|
|||
|
||||
pargs.extend(hiera_key)
|
||||
|
||||
rc, output, err = run_cmd("{} -c {} {}".format(
|
||||
rc, output, err = run_cmd("{0} -c {1} {2}".format(
|
||||
ANSIBLE_HIERA_BIN, ANSIBLE_HIERA_CFG, hiera_key[0]))
|
||||
|
||||
return output.strip()
|
||||
|
|
|
@ -121,7 +121,7 @@ class LookupModule(LookupBase):
|
|||
return sort_parameter
|
||||
|
||||
if not isinstance(sort_parameter, list):
|
||||
raise AnsibleError(u"Error. Sort parameters must be a list, not [ {} ]".format(sort_parameter))
|
||||
raise AnsibleError(u"Error. Sort parameters must be a list, not [ {0} ]".format(sort_parameter))
|
||||
|
||||
for item in sort_parameter:
|
||||
self._convert_sort_string_to_constant(item)
|
||||
|
@ -160,7 +160,7 @@ class LookupModule(LookupBase):
|
|||
return (result - datetime.datetime(1970, 1, 1)). total_seconds()
|
||||
else:
|
||||
# failsafe
|
||||
return u"{}".format(result)
|
||||
return u"{0}".format(result)
|
||||
|
||||
def run(self, terms, variables, **kwargs):
|
||||
|
||||
|
|
|
@ -154,14 +154,14 @@ class LookupModule(LookupBase):
|
|||
if self.paramvals['length'].isdigit():
|
||||
self.paramvals['length'] = int(self.paramvals['length'])
|
||||
else:
|
||||
raise AnsibleError("{} is not a correct value for length".format(self.paramvals['length']))
|
||||
raise AnsibleError("{0} is not a correct value for length".format(self.paramvals['length']))
|
||||
|
||||
# Set PASSWORD_STORE_DIR if directory is set
|
||||
if self.paramvals['directory']:
|
||||
if os.path.isdir(self.paramvals['directory']):
|
||||
os.environ['PASSWORD_STORE_DIR'] = self.paramvals['directory']
|
||||
else:
|
||||
raise AnsibleError('Passwordstore directory \'{}\' does not exist'.format(self.paramvals['directory']))
|
||||
raise AnsibleError('Passwordstore directory \'{0}\' does not exist'.format(self.paramvals['directory']))
|
||||
|
||||
def check_pass(self):
|
||||
try:
|
||||
|
@ -180,7 +180,7 @@ class LookupModule(LookupBase):
|
|||
# if pass returns 1 and return string contains 'is not in the password store.'
|
||||
# We need to determine if this is valid or Error.
|
||||
if not self.paramvals['create']:
|
||||
raise AnsibleError('passname: {} not found, use create=True'.format(self.passname))
|
||||
raise AnsibleError('passname: {0} not found, use create=True'.format(self.passname))
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
|
@ -199,7 +199,7 @@ class LookupModule(LookupBase):
|
|||
newpass = self.get_newpass()
|
||||
datetime = time.strftime("%d/%m/%Y %H:%M:%S")
|
||||
msg = newpass + '\n' + '\n'.join(self.passoutput[1:])
|
||||
msg += "\nlookup_pass: old password was {} (Updated on {})\n".format(self.password, datetime)
|
||||
msg += "\nlookup_pass: old password was {0} (Updated on {1})\n".format(self.password, datetime)
|
||||
try:
|
||||
check_output2(['pass', 'insert', '-f', '-m', self.passname], input=msg)
|
||||
except (subprocess.CalledProcessError) as e:
|
||||
|
@ -211,7 +211,7 @@ class LookupModule(LookupBase):
|
|||
# use pwgen to generate the password and insert values with pass -m
|
||||
newpass = self.get_newpass()
|
||||
datetime = time.strftime("%d/%m/%Y %H:%M:%S")
|
||||
msg = newpass + '\n' + "lookup_pass: First generated by ansible on {}\n".format(datetime)
|
||||
msg = newpass + '\n' + "lookup_pass: First generated by ansible on {0}\n".format(datetime)
|
||||
try:
|
||||
check_output2(['pass', 'insert', '-f', '-m', self.passname], input=msg)
|
||||
except (subprocess.CalledProcessError) as e:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue