Python 2.6 str.format() compatibility fixes.

This commit is contained in:
Matt Clay 2018-01-10 12:03:25 -08:00
parent 95ff8f1a90
commit 797664d9cb
20 changed files with 43 additions and 62 deletions

View file

@ -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(

View file

@ -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()

View file

@ -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):

View file

@ -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: