228228
229229from ansible .module_utils .ansible_freeipa_module import \
230230 IPAAnsibleModule , compare_args_ipa , gen_add_del_lists , gen_add_list , \
231- gen_intersection_list , api_get_domain , ensure_fqdn , netaddr , to_text
231+ gen_intersection_list , concat_attr_list , api_get_domain , ensure_fqdn , \
232+ netaddr , to_text
232233
233234
234235def find_sudorule (module , name ):
@@ -505,18 +506,28 @@ def main():
505506 # Set res_find to empty dict for next step
506507 res_find = {}
507508
508- # Generate addition and removal lists
509+ # Generate addition and removal lists.
510+ # `externalhost` adds an entity to the "External host"
511+ # list for `ipasudorule`. Hosts enrolled to IPA are in
512+ # "Hosts" list.
509513 host_add , host_del = gen_add_del_lists (
510- host , res_find .get ('memberhost_host' , []))
514+ host , concat_attr_list (res_find ,
515+ "memberhost_host" ,
516+ "externalhost" ))
511517
512518 hostgroup_add , hostgroup_del = gen_add_del_lists (
513519 hostgroup , res_find .get ('memberhost_hostgroup' , []))
514520
515521 hostmask_add , hostmask_del = gen_add_del_lists (
516522 hostmask , res_find .get ('hostmask' , []))
517523
524+ # `externaluser` adds an entity to the "External user"
525+ # (non-IPA users) list for `ipasudorule`. Users enrolled to
526+ # IPA are in "Users" list.
518527 user_add , user_del = gen_add_del_lists (
519- user , res_find .get ('memberuser_user' , []))
528+ user , concat_attr_list (res_find ,
529+ "memberuser_user" ,
530+ "externaluser" ))
520531
521532 group_add , group_del = gen_add_del_lists (
522533 group , res_find .get ('memberuser_group' , []))
@@ -547,10 +558,9 @@ def main():
547558 # users list.
548559 runasuser_add , runasuser_del = gen_add_del_lists (
549560 runasuser ,
550- (
551- res_find .get ('ipasudorunas_user' , [])
552- + res_find .get ('ipasudorunasextuser' , [])
553- )
561+ concat_attr_list (res_find ,
562+ 'ipasudorunas_user' ,
563+ 'ipasudorunasextuser' )
554564 )
555565
556566 # runasgroup attribute can be used with both IPA and
@@ -560,10 +570,9 @@ def main():
560570 # groups list.
561571 runasgroup_add , runasgroup_del = gen_add_del_lists (
562572 runasgroup ,
563- (
564- res_find .get ('ipasudorunasgroup_group' , [])
565- + res_find .get ('ipasudorunasextgroup' , [])
566- )
573+ concat_attr_list (res_find ,
574+ 'ipasudorunasgroup_group' ,
575+ 'ipasudorunasextgroup' )
567576 )
568577
569578 elif action == "member" :
@@ -577,7 +586,9 @@ def main():
577586 # the sudorule already
578587 if host is not None :
579588 host_add = gen_add_list (
580- host , res_find .get ("memberhost_host" ))
589+ host , concat_attr_list (res_find ,
590+ "memberhost_host" ,
591+ "externalhost" ))
581592 if hostgroup is not None :
582593 hostgroup_add = gen_add_list (
583594 hostgroup , res_find .get ("memberhost_hostgroup" ))
@@ -586,7 +597,9 @@ def main():
586597 hostmask , res_find .get ("hostmask" ))
587598 if user is not None :
588599 user_add = gen_add_list (
589- user , res_find .get ("memberuser_user" ))
600+ user , concat_attr_list (res_find ,
601+ "memberuser_user" ,
602+ "externaluser" ))
590603 if group is not None :
591604 group_add = gen_add_list (
592605 group , res_find .get ("memberuser_group" ))
@@ -620,8 +633,9 @@ def main():
620633 if runasuser is not None :
621634 runasuser_add = gen_add_list (
622635 runasuser ,
623- (list (res_find .get ('ipasudorunas_user' , []))
624- + list (res_find .get ('ipasudorunasextuser' , [])))
636+ concat_attr_list (res_find ,
637+ 'ipasudorunas_user' ,
638+ 'ipasudorunasextuser' )
625639 )
626640 # runasgroup attribute can be used with both IPA and
627641 # non-IPA (external) groups, so we need to compare
@@ -630,8 +644,9 @@ def main():
630644 if runasgroup is not None :
631645 runasgroup_add = gen_add_list (
632646 runasgroup ,
633- (list (res_find .get ("ipasudorunasgroup_group" , []))
634- + list (res_find .get ("ipasudorunasextgroup" , [])))
647+ concat_attr_list (res_find ,
648+ 'ipasudorunasgroup_group' ,
649+ 'ipasudorunasextgroup' )
635650 )
636651
637652 elif state == "absent" :
@@ -650,7 +665,9 @@ def main():
650665 # in sudorule
651666 if host is not None :
652667 host_del = gen_intersection_list (
653- host , res_find .get ("memberhost_host" ))
668+ host , concat_attr_list (res_find ,
669+ "memberhost_host" ,
670+ "externalhost" ))
654671
655672 if hostgroup is not None :
656673 hostgroup_del = gen_intersection_list (
@@ -662,7 +679,9 @@ def main():
662679
663680 if user is not None :
664681 user_del = gen_intersection_list (
665- user , res_find .get ("memberuser_user" ))
682+ user , concat_attr_list (res_find ,
683+ "memberuser_user" ,
684+ "externaluser" ))
666685
667686 if group is not None :
668687 group_del = gen_intersection_list (
@@ -698,10 +717,10 @@ def main():
698717 if runasuser is not None :
699718 runasuser_del = gen_intersection_list (
700719 runasuser ,
701- (
702- list ( res_find . get ( 'ipasudorunas_user' , []))
703- + list ( res_find . get ( 'ipasudorunasextuser' , []) )
704- )
720+ concat_attr_list ( res_find ,
721+ 'ipasudorunas_user' ,
722+ 'ipasudorunasextuser' )
723+
705724 )
706725 # runasgroup attribute can be used with both IPA and
707726 # non-IPA (external) groups, so we need to compare
@@ -710,12 +729,9 @@ def main():
710729 if runasgroup is not None :
711730 runasgroup_del = gen_intersection_list (
712731 runasgroup ,
713- (
714- list (res_find .get (
715- "ipasudorunasgroup_group" , []))
716- + list (res_find .get (
717- "ipasudorunasextgroup" , []))
718- )
732+ concat_attr_list (res_find ,
733+ 'ipasudorunasgroup_group' ,
734+ 'ipasudorunasextgroup' )
719735 )
720736
721737 elif state == "enabled" :
0 commit comments