|
|
@ -154,14 +154,14 @@ class LookupModule(LookupBase):
|
|
|
|
if self.paramvals['length'].isdigit():
|
|
|
|
if self.paramvals['length'].isdigit():
|
|
|
|
self.paramvals['length'] = int(self.paramvals['length'])
|
|
|
|
self.paramvals['length'] = int(self.paramvals['length'])
|
|
|
|
else:
|
|
|
|
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
|
|
|
|
# Set PASSWORD_STORE_DIR if directory is set
|
|
|
|
if self.paramvals['directory']:
|
|
|
|
if self.paramvals['directory']:
|
|
|
|
if os.path.isdir(self.paramvals['directory']):
|
|
|
|
if os.path.isdir(self.paramvals['directory']):
|
|
|
|
os.environ['PASSWORD_STORE_DIR'] = self.paramvals['directory']
|
|
|
|
os.environ['PASSWORD_STORE_DIR'] = self.paramvals['directory']
|
|
|
|
else:
|
|
|
|
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):
|
|
|
|
def check_pass(self):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -180,7 +180,7 @@ class LookupModule(LookupBase):
|
|
|
|
# if pass returns 1 and return string contains 'is not in the password store.'
|
|
|
|
# if pass returns 1 and return string contains 'is not in the password store.'
|
|
|
|
# We need to determine if this is valid or Error.
|
|
|
|
# We need to determine if this is valid or Error.
|
|
|
|
if not self.paramvals['create']:
|
|
|
|
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:
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
else:
|
|
|
@ -199,7 +199,7 @@ class LookupModule(LookupBase):
|
|
|
|
newpass = self.get_newpass()
|
|
|
|
newpass = self.get_newpass()
|
|
|
|
datetime = time.strftime("%d/%m/%Y %H:%M:%S")
|
|
|
|
datetime = time.strftime("%d/%m/%Y %H:%M:%S")
|
|
|
|
msg = newpass + '\n' + '\n'.join(self.passoutput[1:])
|
|
|
|
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:
|
|
|
|
try:
|
|
|
|
check_output2(['pass', 'insert', '-f', '-m', self.passname], input=msg)
|
|
|
|
check_output2(['pass', 'insert', '-f', '-m', self.passname], input=msg)
|
|
|
|
except (subprocess.CalledProcessError) as e:
|
|
|
|
except (subprocess.CalledProcessError) as e:
|
|
|
@ -211,7 +211,7 @@ class LookupModule(LookupBase):
|
|
|
|
# use pwgen to generate the password and insert values with pass -m
|
|
|
|
# use pwgen to generate the password and insert values with pass -m
|
|
|
|
newpass = self.get_newpass()
|
|
|
|
newpass = self.get_newpass()
|
|
|
|
datetime = time.strftime("%d/%m/%Y %H:%M:%S")
|
|
|
|
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:
|
|
|
|
try:
|
|
|
|
check_output2(['pass', 'insert', '-f', '-m', self.passname], input=msg)
|
|
|
|
check_output2(['pass', 'insert', '-f', '-m', self.passname], input=msg)
|
|
|
|
except (subprocess.CalledProcessError) as e:
|
|
|
|
except (subprocess.CalledProcessError) as e:
|
|
|
|