Skip to content

Commit

Permalink
ipauser: Extend email addresses with default email domain if no domai…
Browse files Browse the repository at this point in the history
…n is set

If there is no domain set for email addresses, extend the email addresses
with the default email domain that is gathered from the config_show output.

This fixes RHBZ#1747413 ([ansible-freeipa] user module throwing an error if..)
  • Loading branch information
t-woerner committed Dec 12, 2019
1 parent b9790e0 commit bc3d3f4
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion plugins/modules/ipauser.py
Expand Up @@ -460,7 +460,8 @@
from ansible.module_utils._text import to_text
from ansible.module_utils.ansible_freeipa_module import temp_kinit, \
temp_kdestroy, valid_creds, api_connect, api_command, date_format, \
compare_args_ipa, module_params_get, api_check_param, api_get_realm
compare_args_ipa, module_params_get, api_check_param, api_get_realm, \
api_command_no_name
import six


Expand Down Expand Up @@ -646,6 +647,14 @@ def check_parameters(module, state, action,
module.fail_json(msg="certmapdata: subject is missing")


def extend_emails(email, default_email_domain):
if email is not None:
return [ "%s@%s" % (_email, default_email_domain)
if "@" not in _email else _email
for _email in email]
return email


def gen_certmapdata_args(certmapdata):
certificate = certmapdata.get("certificate")
issuer = certmapdata.get("issuer")
Expand Down Expand Up @@ -883,6 +892,17 @@ def main():

server_realm = api_get_realm()

# Default email domain

result = api_command_no_name(ansible_module, "config_show", {})
default_email_domain = result["result"]["ipadefaultemaildomain"][0]

# Extend email addresses

email = extend_emails(email, default_email_domain)

# commands

commands = []

for user in names:
Expand Down Expand Up @@ -949,6 +969,10 @@ def main():
certmapdata, noprivate, nomembers, preserve,
update_password)

# Extend email addresses

email = extend_emails(email, default_email_domain)

elif isinstance(user, str) or isinstance(user, unicode):
name = user
else:
Expand Down

0 comments on commit bc3d3f4

Please sign in to comment.