Browse Source

handle folder on creation

main
Markus Bergholz 1 month ago
parent
commit
677a25a0d7
Signed by: m GPG Key ID: B45724801354B174
  1. 1
      README.md
  2. 60
      plugins/modules/password.py

1
README.md

@ -139,6 +139,7 @@ CAUTION ⚠ removes files and folders - recursive!
| `favorite` | whether the password should be marked as favourite or not |
| `state` | `present` or `absent` |
| `update_password` | When to update a password. `on_create` (default) will write the password only if the password record is created. `always` will also update the password if it's exist and the requested password differs from existing. |
| `folder` | Name of the folder where the password must be saved (_works currently only on createion_) |

60
plugins/modules/password.py

@ -34,7 +34,8 @@ def main():
username = dict(required=False, type='str'),
url = dict(required=False, type='str'),
notes = dict(required=False, type='str'),
favorite = dict(required=False, type='bool', default=False)
favorite = dict(required=False, type='bool', default=False),
folder = dict(required=False, type='str')
),
supports_check_mode=True
)
@ -49,21 +50,22 @@ def main():
state = module.params.get('state')
favorite = module.params.get('favorite')
update_password = module.params.get('update_password')
folder = module.params.get('folder')
retval = nc.get_password(name)
if state == 'present':
if len(retval) == 1:
# update password
if len(retval) == 1:
# update password
if password == retval[0].get('password'):
module.exit_json(changed = False, password=retval)
elif update_password == 'always':
obj = {
'id': retval[0].get('id'),
'password': password,
'label': name
'id': retval[0].get('id'),
'password': password,
'label': name
}
if notes:
@ -86,34 +88,40 @@ def main():
else:
module.exit_json(changed = False, password=retval)
elif len(retval) == 0:
# create password
obj = {
'password': password,
'label': name
}
elif len(retval) == 0:
# create password
obj = {
'password': password,
'label': name
}
if folder:
if nc.get_passwords_folder(folder):
obj['folder'] = nc.get_passwords_folder(folder)
else:
obj['folder'] = nc.create_passwords_folder(folder).get('id')
if notes:
obj['notes'] = notes
if notes:
obj['notes'] = notes
if username:
obj['username'] = username
if username:
obj['username'] = username
if url:
obj['url'] = url
if url:
obj['url'] = url
if favorite:
obj['favorite'] = favorite
if favorite:
obj['favorite'] = favorite
retval = {}
if not module.check_mode:
retval = nc.create_password(obj)
retval = {}
if not module.check_mode:
retval = nc.create_password(obj)
module.exit_json(changed = True, password=retval)
module.exit_json(changed = True, password=retval)
else:
raise AnsibleError('More than one password identifies. Cannot continue')
else:
raise AnsibleError('More than one password identifies. Cannot continue')
elif state == 'absent':
if len(retval) == 1:

Loading…
Cancel
Save