
    Vh׈                     J   d dl mZmZmZ eZdZdZdZd dl	Z	d dl
Z
d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZmZmZmZmZmZmZmZmZ d dlmZ 	 d dlm Z  dZ! G d de#      Z$d Z% G d de#      Z& G d de&      Z' G d de&      Z(d Z)e*dk(  r e)        yy# e"$ r dZ!Y Iw xY w)    )absolute_importdivisionprint_functiona"  
module: iosxr_user
author:
- Trishna Guha (@trishnaguha)
- Sebastiaan van Doesselaar (@sebasdoes)
- Kedar Kekan (@kedarX)
short_description: Module to manage the aggregates of local users.
description:
- This module provides declarative management of the local usernames configured on
  network devices. It allows playbooks to manage either individual usernames or the
  aggregate of usernames in the current running config. It also supports purging usernames
  from the configuration that are not explicitly defined.
version_added: 1.0.0
extends_documentation_fragment:
- cisco.iosxr.iosxr
notes:
- This module works with connection C(network_cli) and C(netconf). See L(the IOS-XR
  Platform Options,../network/user_guide/platform_iosxr.html).
options:
  aggregate:
    description:
    - The set of username objects to be configured on the remote Cisco IOS XR device.
      The list entries can either be the username or a hash of username and properties.
      This argument is mutually exclusive with the C(name) argument.
    aliases:
    - users
    - collection
    type: list
    elements: dict
    suboptions:
      name:
        description:
        - The username to be configured on the Cisco IOS XR device. This argument accepts
          a string value and is mutually exclusive with the C(aggregate) argument. Please
          note that this option is not same as C(provider username).
        type: str
        required: true
      configured_password:
        description:
        - The password to be configured on the Cisco IOS XR device. The password needs
          to be provided in clear text. Password is encrypted on the device when used
          with I(cli) and by Ansible when used with I(netconf) using the same MD5 hash
          technique with salt size of 3. Please note that this option is not same as C(provider
          password).
        type: str
      update_password:
        description:
        - Since passwords are encrypted in the device running config, this argument will
          instruct the module when to change the password.  When set to C(always), the
          password will always be updated in the device and when set to C(on_create) the
          password will be updated only if the username is created.
        type: str
        choices:
        - on_create
        - always
      group:
        description:
        - Configures the group for the username in the device running configuration. The
          argument accepts a string value defining the group name. This argument does
          not check if the group has been configured on the device.
        type: str
        aliases:
        - role
      groups:
        description:
        - Configures the groups for the username in the device running configuration.
          The argument accepts a list of group names. This argument does not check if
          the group has been configured on the device. It is similar to the aggregate
          command for usernames, but lets you configure multiple groups for the user(s).
        type: list
        elements: str
      admin:
        description:
        - Enters into administration configuration mode for making config changes to the
          device.
        - Applicable only when using network_cli transport
        type: bool
      state:
        description:
        - Configures the state of the username definition as it relates to the device
          operational configuration. When set to I(present), the username(s) should be
          configured in the device active configuration and when set to I(absent) the
          username(s) should not be in the device active configuration
        type: str
        choices:
        - present
        - absent
      public_key:
        description:
        - Configures the contents of the public keyfile to upload to the IOS-XR node.
          This enables users to login using the accompanying private key. IOS-XR only
          accepts base64 decoded files, so this will be decoded and uploaded to the node.
          Do note that this requires an OpenSSL public key file, PuTTy generated files
          will not work! Mutually exclusive with public_key_contents. If used with multiple
          users in aggregates, then the same key file is used for all users.
        type: str
      public_key_contents:
        description:
        - Configures the contents of the public keyfile to upload to the IOS-XR node.
          This enables users to login using the accompanying private key. IOS-XR only
          accepts base64 decoded files, so this will be decoded and uploaded to the node.
          Do note that this requires an OpenSSL public key file, PuTTy generated files
          will not work! Mutually exclusive with public_key.If used with multiple users
          in aggregates, then the same key file is used for all users.
        type: str
  name:
    description:
    - The username to be configured on the Cisco IOS XR device. This argument accepts
      a string value and is mutually exclusive with the C(aggregate) argument. Please
      note that this option is not same as C(provider username).
    type: str
  configured_password:
    description:
    - The password to be configured on the Cisco IOS XR device. The password needs
      to be provided in clear text. Password is encrypted on the device when used
      with I(cli) and by Ansible when used with I(netconf) using the same MD5 hash
      technique with salt size of 3. Please note that this option is not same as C(provider
      password).
    type: str
  update_password:
    description:
    - Since passwords are encrypted in the device running config, this argument will
      instruct the module when to change the password.  When set to C(always), the
      password will always be updated in the device and when set to C(on_create) the
      password will be updated only if the username is created.
    type: str
    default: always
    choices:
    - on_create
    - always
  group:
    description:
    - Configures the group for the username in the device running configuration. The
      argument accepts a string value defining the group name. This argument does
      not check if the group has been configured on the device.
    type: str
    aliases:
    - role
  groups:
    description:
    - Configures the groups for the username in the device running configuration.
      The argument accepts a list of group names. This argument does not check if
      the group has been configured on the device. It is similar to the aggregate
      command for usernames, but lets you configure multiple groups for the user(s).
    type: list
    elements: str
  purge:
    description:
    - Instructs the module to consider the resource definition absolute. It will remove
      any previously configured usernames on the device with the exception of the
      `admin` user and the current defined set of users.
    type: bool
    default: false
  admin:
    description:
    - Enters into administration configuration mode for making config changes to the
      device.
    - Applicable only when using network_cli transport
    type: bool
    default: false
  state:
    description:
    - Configures the state of the username definition as it relates to the device
      operational configuration. When set to I(present), the username(s) should be
      configured in the device active configuration and when set to I(absent) the
      username(s) should not be in the device active configuration
    type: str
    default: present
    choices:
    - present
    - absent
  public_key:
    description:
    - Configures the contents of the public keyfile to upload to the IOS-XR node.
      This enables users to login using the accompanying private key. IOS-XR only
      accepts base64 decoded files, so this will be decoded and uploaded to the node.
      Do note that this requires an OpenSSL public key file, PuTTy generated files
      will not work! Mutually exclusive with public_key_contents. If used with multiple
      users in aggregates, then the same key file is used for all users.
    type: str
  public_key_contents:
    description:
    - Configures the contents of the public keyfile to upload to the IOS-XR node.
      This enables users to login using the accompanying private key. IOS-XR only
      accepts base64 decoded files, so this will be decoded and uploaded to the node.
      Do note that this requires an OpenSSL public key file, PuTTy generated files
      will not work! Mutually exclusive with public_key.If used with multiple users
      in aggregates, then the same key file is used for all users.
    type: str

requirements:
- ncclient >= 0.5.3 when using netconf
- lxml >= 4.1.1 when using netconf
- base64 when using I(public_key_contents) or I(public_key)
aQ  
- name: create a new user
  cisco.iosxr.iosxr_user:
    name: ansible
    configured_password: mypassword
    state: present
- name: create a new user in admin configuration mode
  cisco.iosxr.iosxr_user:
    name: ansible
    configured_password: mypassword
    admin: true
    state: present
- name: remove all users except admin
  cisco.iosxr.iosxr_user:
    purge: true
- name: set multiple users to group sys-admin
  cisco.iosxr.iosxr_user:
    aggregate:
      - name: netop
      - name: netend
    group: sysadmin
    state: present
- name: set multiple users to multiple groups
  cisco.iosxr.iosxr_user:
    aggregate:
      - name: netop
      - name: netend
    groups:
      - sysadmin
      - root-system
    state: present
- name: Change Password for User netop
  cisco.iosxr.iosxr_user:
    name: netop
    configured_password: '{{ new_password }}'
    update_password: always
    state: present
- name: Add private key authentication for user netop
  cisco.iosxr.iosxr_user:
    name: netop
    state: present
    public_key_contents: "{{ lookup('file', '/home/netop/.ssh/id_rsa.pub' }}"
a  
commands:
  description: The list of configuration mode commands to send to the device
  returned: always
  type: list
  sample:
    - username ansible secret password group sysadmin
    - username admin secret admin
xml:
  description: NetConf rpc xml sent to device with transport C(netconf)
  returned: always (empty list when no xml rpc to send)
  type: list
  sample:
    - '<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
    <aaa xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-aaa-lib-cfg">
    <usernames xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-aaa-locald-cfg">
    <username xc:operation="merge">
    <name>test7</name>
    <usergroup-under-usernames>
    <usergroup-under-username>
    <name>sysadmin</name>
    </usergroup-under-username>
    </usergroup-under-usernames>
    <secret>$1$ZsXC$zZ50wqhDC543ZWQkkAHLW0</secret>
    </username>
    </usernames>
    </aaa>
    </config>'
N)deepcopy)partial)AnsibleModule)remove_default_spec)		build_xml	copy_fileetree_findallget_capabilities
get_configget_connection
is_cliconf
is_netconfload_config)Version)	b64decodeTFc                   *    e Zd Zd Zd Zd Zd Zd Zy)PublicKeyManagerc                      || _         || _        y N)_module_result)selfmoduleresults      j/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/cisco/iosxr/plugins/modules/iosxr_user.py__init__zPublicKeyManager.__init__=  s        c                    | j                   j                  d   rd}n| j                   j                  d   }| j                   j                  d   r| j                   j                  d   }nL| j                   j                  d   r3t        | j                   j                  d   d      }|j                         }j	                         d   }t        |      }t        d|z  d      }|j                  |       |j                          d|z  S )	zVIOS-XR only accepts base64 decoded files, this converts the public key to a temp file.	aggregatenamepublic_key_contents
public_keyr   z/tmp/publickey_%s.b64wb)r   paramsopenreadsplitr   writeclose)r   r#   keyreadfile	splitfile	base64key
base64files          r   convert_key_to_base64z&PublicKeyManager.convert_key_to_base64A  s    <<{+D<<&&v.D<<45,,%%&;<C\\  .DLL//=sCH--/CIIKN	i(	1T:DA
#&$//r    c                     | j                   j                  d   rd}n| j                   j                  d   }|}d|z  }t        | j                   ||       y)z^Copy key to IOS-XR node. We use SFTP because older IOS-XR versions don't handle SCP very well.r"   r#   z/harddisk:/publickey_%s.b64N)r   r)   r   )r   base64keyfiler#   srcdsts        r   copy_key_to_nodez!PublicKeyManager.copy_key_to_nodeV  sN     <<{+D<<&&v.D+t4$,,S)r    c                     | j                   j                  j                  d      }t        | j                         }|r|j	                  d       |j	                  |dd      }|r|j	                  d       |S )z"Add or remove key based on commandadminzyes/noyes)promptanswerexit)r   r)   getr   send_command)r   commandr;   connouts        r   addremovekeyzPublicKeyManager.addremovekeyc  sh    ##''0dll+g&Gf%
r    c                 *   | j                   j                  d   dk(  r| j                   j                  s| j                         }| j	                  |       | j                   j                  d   r@| j                   j                  d   D ]  }d|z  }| j                  |        | j                  S d| j                   j                  d   d| j                   j                  d   d}| j                  |       | j                  S | j                   j                  d   d	k(  r| j                   j                  s| j                   j                  d   r@| j                   j                  d   D ]  }d
|z  }| j                  |        | j                  S d
| j                   j                  d   z  }| j                  |       | j                  S | j                   j                  d   du r)| j                   j                  sd}| j                  |       | j                  S )Nstatepresentr"   zRcrypto key import authentication rsa username %s harddisk:/publickey_aggregate.b64z.crypto key import authentication rsa username r#   z harddisk:/publickey_z.b64absentz1crypto key zeroize authentication rsa username %spurgeTz)crypto key zeroize authentication rsa all)r   r)   
check_moder4   r9   rE   r   )r   r/   usercmdtodos       r   runzPublicKeyManager.runp  s   <<w'94<<**002%%c*<<&&{3 $ 3 3K @ 3p#%   ))'238 ||; 4  <<..v68K8KF8SU  %%g." ||! \\  )X5<<**<<&&{3 $ 3 3K @ 3"UY]"^))'23 || R++F3G %%g. || \\  )T1<<**E!!'*||r    N)__name__
__module____qualname__r   r4   r9   rE   rN    r    r   r   r   <  s    0**#r    r   c                 *    |D ]  }|d   | k(  s|c S  y )Nr#   rR   )r#   lstos      r   search_obj_in_listrV     s'     V9H r    c                        e Zd ZddZd Zd Zy)
ConfigBaseNc                 \    || _         || _        t               | _        t               | _        y r   )r   r   list_want_have)r   r   r   flags       r   r   zConfigBase.__init__  s"    V
V
r    c                 x   |j                  |      s| j                  j                  |   }nR| j                  j                  |   j                  dd      }| j                  j                  |   } |||          ||   }t               j                  d|z        }t        ||f      r ||| j                         |S )Ntypestrzvalidate_%s)r@   r   r)   argument_spec _CHECK_ARGUMENT_TYPES_DISPATCHERglobalsall)r   r/   itemvalue
value_typetype_checker	validators          r   get_param_valuezConfigBase.get_param_value  s    xx}LL'',E 33C8<<VUKJ<<HHTLc#IE IMM-#"56	y!"eT\\*r    c                    | j                   j                  d   }t               }|s| j                   j                  d   s| j                   j                  d   rn| j                   j                  d   s| j                   j                  d       nzd| j                   j                  d   ig}n]|D ]X  }t	        |t
              s|j                  d|i       'd|vr| j                   j                  d       H|j                  |       Z |D ]`  }t        | j                  |      } |d      |d<    |d	      |d	<    |d
      |d
<    |d      |d<   | j                  j                  |       b y )Nr"   r#   rJ   zusername is requiredmsgzname is required)re   configured_passwordgroupgroupsrG   )
r   r)   rZ   	fail_json
isinstancedictappendr   rj   r[   )r   usersr"   re   	get_values        r   map_params_to_objzConfigBase.map_params_to_obj  sQ   ##K0F	<<&&v.4<<3F3Fw3O\\((0&&+A&B$dll&9&9&&ABC	 +!$-$$fd^44'LL**/A*B$$T*+  	$D 4 44@I*34I*JD&'%g.DM&x0DN%g.DMJJd#	$r    r   )rO   rP   rQ   r   rj   rw   rR   r    r   rX   rX     s    &$r    rX   c                   0     e Zd Z fdZd Zd Zd Z xZS )CliConfigurationc                 .    t         t        |   ||       y r   )superry   r   r   r   r   	__class__s      r   r   zCliConfiguration.__init__  s    .vv>r    c                    t        | j                  d      }d|v ry |j                         j                  d      j	                  d      }|D ]  }|j                         j                         }|d   j                         j	                         d   }d }t        |      dkD  r.|d   j                         j	                         }|d   dk(  r|d   }|dd |d	}| j                  j                  |        y )
Nusername)config_filterzNo such configuration item!r   r'   ro   rH   )r#   rG   rn   ro   )	r   r   striprstripr,   
splitlineslenr\   rt   )	r   dataru   rL   user_configr#   ro   group_or_secretobjs	            r   map_config_to_objz"CliConfiguration.map_config_to_obj  s    $,,jA'4/

##C(..s3 	#D**,113Kq>'')//1!4DE;!#"-a."6"6"8">">"@"1%0+A.E)D[`aCJJc"	#r    c                    t               }| j                  D ]`  }|d   }|d   }t        || j                        }|dk(  r|r|j	                  d|z          @|dk(  r|s}d|z   }|j	                  |       |d   r|j	                  |dz   |d   z          |d	   r|j	                  |d
z   |d	   z          |d   s|d   D ]  }|j	                  |d
z   |z           |dk(  s|sd|z   }| j
                  j                  d   dk(  r|d   r|j	                  |dz   |d   z          |d	   r'|d	   |d	   k7  r|j	                  |d
z   |d	   z          9|d   s@|d   D ]  }|j	                  |d
z   |z           c | j
                  j                  d   rz| j                  D cg c]  }|d   	 }	}| j                  D cg c]  }|d   	 }
}t        |
      j                  t        |	            D ]  }|dk7  s	|j	                  d|z          d|v r| j
                  j                  d       g | j                  d<   |r| j
                  j                   }| j
                  j                  d   }t        | j
                  |||      }|rt        |      | j                  d<   || j                  d<   d| j                  d<   y y c c}w c c}w )Nr#   rG   rI   zno username rH   z	username rn   z secret ro   z group rp   update_passwordalwaysrJ   r;   zno username %szno username adminz!cannot delete the `admin` accountrl   commands)commitr;   prepareddiffTchanged)rZ   r[   rV   r\   rt   r   r)   set
differencerq   r   rK   r   rs   )r   r   wr#   rG   obj_in_haveuser_cmdro   x
want_users
have_usersre   r   r;   r   s                  r   map_obj_to_commandsz$CliConfiguration.map_obj_to_commands  s   6 	FAV9DgJE,T4::>K [ 56)#K&-)*+OOHz$9A>S<T$TUW:OOHy$81W:$EFx[!"8 F 9(<u(DEF )#&-<<&&'89XE!LaJbOOHz$9A>S<T$TUW:!G*G0D"DOOHy$81W:$EFx[!"8 F 9(<u(DEF9	F> <<w'-1ZZ8!F)8J8-1ZZ8!F)8J8J223z?C =7?OO$4t$;<= (*LL""'J"K#%Z 000FLL''0Et||XfERD'+T':V$'/DLL$&*DLL#  98s   "K>Kc                 z    | j                          | j                          | j                          | j                  S r   )rw   r   r   r   )r   s    r   rN   zCliConfiguration.run&  s0        "||r    )rO   rP   rQ   r   r   r   rN   __classcell__r}   s   @r   ry   ry     s    ?#,5+nr    ry   c                   0     e Zd Z fdZd Zd Zd Z xZS )NCConfigurationc                     t         t        |   ||       t        j                         | _        t        j                         | _        y r   )r{   r   r   collectionsOrderedDict_locald_meta_locald_group_metar|   s      r   r   zNCConfiguration.__init__/  s6    ot-ff='335"-"9"9";r    c                 t    d}t        j                  ||z         j                         d   j                         S )zw
        Generate MD5 hash with randomly generated salt size of 3.
        :param arg:
        :return passwd:
        z1openssl passwd -salt `openssl rand -base64 3` -1 r   )ospopen	readlinesr   )r   argcmds      r   generate_md5_hashz!NCConfiguration.generate_md5_hash4  s4     Bxxc	",,.q17799r    c                    |rt        |      t        d      kD  r| j                  j                  dddddfddddd	fd
ddifdddifdddddfddddfddddfg       | j                  j                  dddddfddddd	fd
ddifdddifdddddfdddddfddddfg       nv| j                  j                  dddddfddddd	fd
ddifddddfg       | j                  j                  dddddfddddd	fd
ddifdddddfdddddfddddfg       | j                  j
                  d    }t        d!d"#      }t        | j                  d$|%      }t        |d      }t               }|D ]  }t        |d&      }|j                  |d'   j                         t        |      }	|	d(k(  r-| j                  j                  |d'   j                  d d d)       n|	d*k(  r:| j                  j                  |d'   j                  |d(   j                  d d)       ns|	d*kD  rnt        |      }
t        |
       t               }|
D ]  }|j                  |j                          | j                  j                  |d'   j                  d |d)       |s!t        |      t        d      kD  s:t        |d+      }t        | j                        d'kD  s`| j                  d,   j                  |d'   j                  -        t               }t               }d }| j                  D cg c].  }|j!                  d.      st#        |j!                  d.            0 }}|d/k(  rmd0}| j$                  D ]Z  }|d&   |v st'        |d&   | j                        }|rt        |      t        d      kD  r|d.   |d.<   d |d1<   |j                  |       \ n|d2k(  rd3}| j$                  D ]  }t'        |d&   | j                        }|d&   |vr|rZt        |      t        d      kD  rC| j)                  |d1         |d1<   |d,   d(z   }t+        |      |d.<   |j                  |       d|d4<   | j)                  |d1         |d1<   |j                  |       |d5   |j                  |       |d6   |d6   D ]&  }||d5<   |j                  |j-                                ( |r&t        |      t        d      kD  r|rd|d4<   |d.   |d.<   | j                  j
                  d7   d8k(  r.|d1   )| j)                  |d1         |d1<   |j                  |       nd |d1<   |d5   |d5   |d5   k7  r|j                  |       |d6   |d6   D ]&  }||d5<   |j                  |j-                                (  t               }| j                  j
                  d9   ry| j$                  D cg c]  }|d&   	 }}| j                  D cg c]  }|d&   	 }}t/        |      j1                  t/        |            D ]  }|d:k7  s	|j                  d&|i        g | j2                  d;<   t               }|~|r(|j                  t        d!| j                  ||<             |r(|j                  t        d!| j                  ||<             |r(|j                  t        d!| j                  |d0<             d }|r1| j                  j4                   }t7        | j                  ||||=      }|rN| j                  j8                  rt;        |>      | j2                  d?<   || j2                  d;<   d| j2                  d@<   y y c c}w c c}w c c}w )ANz7.0
aaa_localdzaaa/usernamesT)xpathtagnsr   zaaa/usernames/username	operation)r   r   attribza:namer   zaaa/usernames/username/nameza:ordering_indexz%aaa/usernames/username/ordering-indexsecretzaaa/usernames/username/secretedit)r   r   r   za:typez"aaa/usernames/username/secret/typetype5)r   rf   za:configured_passwordz%aaa/usernames/username/secret/secret5)r   r   
usergroupsz0aaa/usernames/username/usergroup-under-usernames	usergroupzIaaa/usernames/username/usergroup-under-usernames/usergroup-under-usernameza:groupzNaaa/usernames/username/usergroup-under-usernames/usergroup-under-username/namerG   aaafilter)opcoderunning)sourcer   r#   r   r'   )r#   ro   rp      zordering-index)ordering_indexr   rI   deletern   rH   merger_   ro   rp   r   r   rJ   r;   xml)xmapr)   r   )r   r   nc_get_filterr   r   r   )r   r   updater   r   r)   r
   r   r   rZ   rt   textr   r\   iternextr@   intr[   rV   r   r`   copyr   r   r   rK   r   _diffrs   )r   
os_versionrG   _get_filterr   elementsru   element	name_list	list_size	name_itertmp_listr#   r   locald_paramslocald_group_paramsr   rL   ordering_index_list	want_itemr   new_ordering_indexro   purge_paramsr   r   r   re   _edit_filter_listr   r   s                                  r   map_obj_to_xml_rpcz"NCConfiguration.map_obj_to_xml_rpc=  s   '*->$$!_TQU#VW"":4S^_ )FGH''3Z)[\ %D#')/ )MX_`a/"IX^_#0 ##**!_TQU#VW"":4S^_ )FGH''3Z)[\$%W#')/ $%p#')/ "%u)/1!F $$!_TQU#VW"":4S^_ )FGH/"APVW ##**!_TQU#VW"":4S^_ )FGH$%W#')/ $%p#')/ "%u)// D ##G,h7T\\);W *5 	QG%gv6ILL1**+IIA~

!!9Q<+<+<tW["\]a

!!&q\..19J9JVZ[ Q O	Y6% /DOODII./ 

!!9Q<+<+<tW_"`agj1GENB!.w8H!Itzz?Q&JJrN))9J9O9O)P+	Q. "f8<


04dhhO_F`C)*+
 
 HF!ZZ 4	V$-"4Yv5F

"SK!gj&9GEN&J6ABR6S	"237;I34!((34 iF!ZZ .I	061BDJJOV$E1!gj&9GEN&J;?;Q;Q%&;<<	"78 .A-Dq-H*69:L6M	"23+223EF,3	&)7;7M7M!"788I34 "((3 )5+229= *6%.x%8 IE16Ig./66y~~7GHI "gj&9GEN&J&07If-:EFV:WI&67++,=>(J%&;<H;?;Q;Q%&;<<	"78 &,,Y7;?	"78 "'*6%g.+g2FF+229="8,8%.x%8 IE16Ig./66y~~7GHIY.I` v<<w'-1ZZ8!F)8J8-1ZZ8!F)8J8J223z?C 87? ''78 !U F!((e$*;*;MZ`a #!((!442%	 !((e$*;*;LYab 000F!)D ||!!'+T':V$"3DLL&*DLL# Q
B 98s   ']">]"]'4],c                     t        | j                        j                  d      j                  d      }| j                          | j	                  |       | j
                  S )Ndevice_infonetwork_os_version)r   r   r@   rw   r   r   )r   r   s     r   rN   zNCConfiguration.run9  sK    %dll377FJJK_`
 
+||r    )rO   rP   rQ   r   r   r   rN   r   r   s   @r   r   r   .  s    <
:z+xr    r   c                  l   t        t        d      t        dd      t        ddddg      t        dd	
      t        d      t        d      t        ddg      t        dd      t        ddddg      	      } t        |       }t        d      |d<   t        |       g d}t        t        dd|ddg      t        dd	
            }|j                  |        t	        ||d      }|j
                  d   s|j
                  d   rt        s|j                  d       d	g d}d }t        |      rt        ||      }nt        |      rt        ||      }|r|j                         }|j
                  d   s|j
                  d   rt        ||      }|j                         } |j                  d!i | y )"z%main entry point for module executionr`   )r_   T)r_   no_logr   	on_create)r_   defaultchoicesboolF)r_   r   role)r_   aliasesrZ   )r_   r   rH   rI   )	r#   rn   r   r;   r%   r$   ro   rp   rG   )requiredr#   ))r#   r"   )r%   r$   )ro   rp   rs   ru   
collection)r_   r   optionsr   )r"   rJ   )ra   mutually_exclusivesupports_check_moder$   r%   znlibrary base64 is required but does not appear to be installed. It can be installed using `pip install base64`rl   )r   warningsNrR   )rs   r   r	   r   r   r)   HAS_B64rq   r   ry   r   r   rN   r   	exit_json)element_specaggregate_specr   ra   r   r   config_objectpubkey_objects           r   mainr   A  s   u eD9%KQYCZ[.U# e,x0%0y9h:OP
L l+N!40N6 ' "l+	
 .M &#- F }}*+v}}\/JL  
 B/FM&(8	F	'7""$}}*+v}}\/J(8""$Fvr    __main__)+
__future__r   r   r   r_   __metaclass__DOCUMENTATIONEXAMPLESRETURNr   r   r   r   	functoolsr   ansible.module_utils.basicr   Oansible_collections.ansible.netcommon.plugins.module_utils.network.common.utilsr	   Hansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.iosxrr
   r   r   r   r   r   r   r   r   Nansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.utils.utilsr   base64r   r   ImportErrorobjectr   rV   rX   ry   r   r   rO   rR   r    r   <module>r     s    A @ BH*X
<  	   4
 
 
 c G
Wv Wt4$ 4$nVz VrPj PfBJ zF ]  Gs   B B"!B"