Anons79 Mini Shell

Directory : /lib/python2.7/site-packages/ansible/modules/network/ios/
Upload File :
Current File : //lib/python2.7/site-packages/ansible/modules/network/ios/ios_user.pyo

�
�Udac@shidd6dgd6dd6ZdZdZdZd	d
lZd	d
lZd	d
lZd	dlmZd	dl	m
Z
d	d
lmZd	dl
mZd	dlmZmZd	dlmZmZd	dlmZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"d�Z#e$d krde#�nd
S(!s1.1tmetadata_versiontpreviewtstatustnetworktsupported_bys{
---
module: ios_user
version_added: "2.4"
author: "Trishna Guha (@trishnaguha)"
short_description: Manage the aggregate of local users on Cisco IOS device
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.
notes:
  - Tested against IOS 15.6
options:
  aggregate:
    description:
      - The set of username objects to be configured on the remote
        Cisco IOS 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']
  name:
    description:
      - The username to be configured on the Cisco IOS 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).
  configured_password:
    description:
      - The password to be configured on the Cisco IOS device. The
        password needs to be provided in clear and it will be encrypted
        on the device.
        Please note that this option is not same as C(provider password).
  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.
    default: always
    choices: ['on_create', 'always']
  password_type:
    description:
      - This argument determines whether a 'password' or 'secret' will be
        configured.
    default: secret
    choices: ['secret', 'password']
    version_added: "2.8"
  hashed_password:
    description:
      - This option allows configuring hashed passwords on Cisco IOS devices.
    suboptions:
      type:
        description:
          - Specifies the type of hash (e.g., 5 for MD5, 8 for PBKDF2, etc.)
          - For this to work, the device needs to support the desired hash type
        type: int
        required: True
      value:
        description:
          - The actual hashed password to be configured on the device
        required: True
    version_added: "2.8"
  privilege:
    description:
      - The C(privilege) argument configures the privilege level of the
        user when logged into the system. This argument accepts integer
        values in the range of 1 to 15.
  view:
    description:
      - Configures the view for the username in the
        device running configuration. The argument accepts a string value
        defining the view name. This argument does not check if the view
        has been configured on the device.
    aliases: ['role']
  sshkey:
    description:
      - Specifies one or more SSH public key(s) to configure
        for the given username.
      - This argument accepts a valid SSH key value.
    version_added: "2.7"
  nopassword:
    description:
      - Defines the username without assigning
        a password. This will allow the user to login to the system
        without being authenticated by a password.
    type: bool
  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 (the current defined set of users).
    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
    default: present
    choices: ['present', 'absent']
extends_documentation_fragment: ios
sd
- name: create a new user
  ios_user:
    name: ansible
    nopassword: True
    sshkey: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
    state: present

- name: create a new user with multiple keys
  ios_user:
    name: ansible
    sshkey:
      - "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
      - "{{ lookup('file', '~/path/to/public_key') }}"
    state: present

- name: remove all users except admin
  ios_user:
    purge: yes

- name: remove all users except admin and these listed users
  ios_user:
    aggregate:
      - name: testuser1
      - name: testuser2
      - name: testuser3
    purge: yes

- name: set multiple users to privilege level 15
  ios_user:
    aggregate:
      - name: netop
      - name: netend
    privilege: 15
    state: present

- name: set user view/role
  ios_user:
    name: netop
    view: network-operator
    state: present

- name: Change Password for User netop
  ios_user:
    name: netop
    configured_password: "{{ new_password }}"
    update_password: always
    state: present

- name: Aggregate of users
  ios_user:
    aggregate:
      - name: ansibletest2
      - name: ansibletest3
    view: network-admin

- name: Add a user specifying password type
  ios_user:
    name: ansibletest4
    configured_password: "{{ new_password }}"
    password_type: password

- name: Add a user with MD5 hashed password
  ios_user:
    name: ansibletest5
    hashed_password:
      type: 5
      value: $3$8JcDilcYgFZi.yz4ApaqkHG2.8/

- name: Delete users with aggregate
  ios_user:
    aggregate:
      - name: ansibletest1
      - name: ansibletest2
      - name: ansibletest3
    state: absent
s�
commands:
  description: The list of configuration mode commands to send to the device
  returned: always
  type: list
  sample:
    - username ansible secret password
    - username admin secret admin
i����N(tdeepcopy(tpartial(t
AnsibleModule(tremove_default_spec(t
get_configtload_config(tios_argument_spect
check_args(t	iteritemscCs>|r:d|kodknr:|jdd|�ndS(Niitmsgs*privilege must be between 1 and 15, got %s(t	fail_json(tvaluetmodule((sH/usr/lib/python2.7/site-packages/ansible/modules/network/ios/ios_user.pytvalidate_privilege�s#cCs$id|d6dd6dd6td6S(Nsno username %stcommandsMThis operation will remove all username related configurations with same nametprompttytanswertnewline(tFalse(tusername((sH/usr/lib/python2.7/site-packages/ansible/modules/network/ios/ios_user.pytuser_del_cmd�s
cCs�|s
dSd|kr^|jd�}tjtj|d��j�j�|d<dj|�Sdtjtj|��j�j�SdS(Nt is
ssh-rsa %s(	tNonetsplitthashlibtmd5tbase64t	b64decodet	hexdigesttuppertjoin(tsshkeytkeyparts((sH/usr/lib/python2.7/site-packages/ansible/modules/network/ios/ios_user.pytsshkey_fingerprint�s,
c
Cst�}|jd}|jd}d�}d�}d�}dd�}x�|D]�}	|	\}
}|
ddkr�|d	r�|||
�q�|jt|
d
��n||
|d�r�|||
d|
d�n||
|d
�r|||
d|
d
�n||
|d	�r*|||
|
d	�n||
|d�r�|dksO|r�|r|||dkr||jddd�n|||
d||
df�q�n||
|d�r�|||
|
d�n||
|d�rQ|
dr�|||
d�q|||
t|
d
��qQqQW|S(Ntupdate_passwordt
password_typecSs+|j|�o*|j|�|j|�kS(N(tget(twantthavetx((sH/usr/lib/python2.7/site-packages/ansible/modules/network/ios/ios_user.pytneeds_updatescSs|jd|d|f�dS(Nsusername %s %stname(tappend(RR+R-((sH/usr/lib/python2.7/site-packages/ansible/modules/network/ios/ios_user.pytaddscSs4|jd|d|jd�|jd�f�dS(Nsusername %s secret %s %sR/ttypeR(R0R*(RR+R-((sH/usr/lib/python2.7/site-packages/ansible/modules/network/ios/ios_user.pytadd_hashed_passwordscSs�|jd�|rZ|jd|d�x|D]}|jd|�q/W|jd�n|jd|d�|jd�dS(Nsip ssh pubkey-chainsusername %sR/skey-hash %stexitsno username %s(R0(RR+R-titem((sH/usr/lib/python2.7/site-packages/ansible/modules/network/ios/ios_user.pytadd_sshs

tstatetabsentR%R/tviewsview %st	privilegesprivilege %stconfigured_passwordtalwaysRs4Can not have both a user password and a user secret.s  Please choose one or the other.s%s %sthashed_passwordt
nopassword(tlisttparamsRR0RR(tupdatesRtcommandsR(R)R.R1R3R6tupdateR+R,((sH/usr/lib/python2.7/site-packages/ansible/modules/network/ios/ios_user.pytmap_obj_to_commands	s@	

			

$
!cCs/tjd|tj�}|r+|jd�SdS(Ns
view (\S+)i(tretsearchtMtgroup(tdatatmatch((sH/usr/lib/python2.7/site-packages/ansible/modules/network/ios/ios_user.pyt
parse_viewHscCsbd|}tj||tj�}g}|r^tjd|j�tj�}|r^|}q^n|S(Nsusername %s(\n\s+key-hash .+$)+skey-hash (\S+ \S+(?: .+)?)$(RERFRGtfindallRH(RItusertsshregextsshcfgtkey_listRJ((sH/usr/lib/python2.7/site-packages/ansible/modules/network/ios/ios_user.pytparse_sshkeyNs
cCs5tjd|tj�}|r1t|jd��SdS(Nsprivilege (\S+)i(RERFRGtintRH(RIRJ((sH/usr/lib/python2.7/site-packages/ansible/modules/network/ios/ios_user.pytparse_privilegeYscCs9d}|r5|j�ddkr5|j�d}n|S(Ni����tpasswordtsecret(RTRU(RR(RIR2((sH/usr/lib/python2.7/site-packages/ansible/modules/network/ios/ios_user.pytparse_password_type_scCst|ddg�}tjd|tj�}|s:t�St�}x�t|�D]�}d|}tj||tj�}dj|�}i	|d6dd6d	|kd	6dd
6dd6t|�d6t	||�d
6t
|�d6t|�d6}|j|�qPW|S(Ntflagss| section usernames(?:^(?:u|\s{2}u))sername (\S+)susername %s .+$s
R/tpresentR7R>R;R=R)R%R:R9(
R	RERLRGR?tsetR$RRVRQRSRKR0(RRIRJt	instancesRMtregextcfgtobj((sH/usr/lib/python2.7/site-packages/ansible/modules/network/ios/ios_user.pytmap_config_to_objfs*	



cCs�|j|�s|j|}n>|j|jdd�}|j|}|||�||}t�jd|�}t||f�r�|||�n|S(NR2tstrsvalidate_%s(R*R@t
argument_spect _CHECK_ARGUMENT_TYPES_DISPATCHERtglobalstall(tkeyR5RRt
value_typettype_checkert	validator((sH/usr/lib/python2.7/site-packages/ansible/modules/network/ios/ios_user.pytget_param_value�s

cCs�|jd}|so|jdr5|jdr5t�S|jdsU|jdd�q�i|jdd6g}nlt�}x`|D]X}t|t�s�|ji|d6�qd|kr�|jdd�q|j|�qWt�}x�|D]�}ttd|d|�}|d	�|d	<|d
�|d
<|d�|d<|d�|d<|d
�|d
<t|d��|d<|d�|d<|j|�q�W|S(Nt	aggregateR/tpurgeRsusername is requiredsname is requiredR5RR;R=R>R:R9R%R7(	R@R?Rt
isinstancetdictR0RRhtrender_key_list(RtusersRiR5tobjectst	get_value((sH/usr/lib/python2.7/site-packages/ansible/modules/network/ios/ios_user.pytmap_params_to_obj�s4

	
	
cCs7g}|r3x$|D]}|jt|��qWn|S(N(R0R'(tssh_keysRPR5((sH/usr/lib/python2.7/site-packages/ansible/modules/network/ios/ios_user.pyRm�s

cs�t�}x�|D]��t�fd�|D�d�}t|dk�ddkf�rm|j�if�q|rxIt��D]8\}}|r�|||kr�|j�|f�q�q�WqqW|S(Nc3s)|]}|d�dkr|VqdS(R/N((t.0ti(tentry(sH/usr/lib/python2.7/site-packages/ansible/modules/network/ios/ios_user.pys	<genexpr>�sR7RX(R?tnextRRcR0R
(R+R,RAR5RdR((RusH/usr/lib/python2.7/site-packages/ansible/modules/network/ios/ios_user.pytupdate_objects�s	
"!cCstdtdddt�dtdtdt��}tdt�dtdt�dtdtdd	d
|�dtdd�d
tdddddg�dtdddddg�dtdd�dtddg�dtdd�dtdddddg��
}t|�}tdt�|d<t|�tdtdddd	d
|dd d!g�d"tdddt��}|j|�|jt�d-d.g}td#|d$|d%t�}t�}|j	dr�|j	dr�|j
d&d'�nt||�itd(6}|r||d)<nt|�}t
|�}	tt||	�|�}
|j	d"r�g|D]}|d^qW}g|	D]}|d^qt}
xBt|
�j|�D](}|d*kr�|
j
t|��q�q�Wn|
|d+<|
r|js�t||
�nt|d(<n|j|�d,S(/s+ main entry point for module execution
    R2RRtrequiredRtno_logR/R;R=RltoptionsR>tboolR(tdefaultR<tchoicest	on_createR)RURTR:R9taliasestroleR%R?R7RXR8RitelementsRnt
collectionRjR`tmutually_exclusivetsupports_check_modesHThe "password" argument is used to authenticate the current connection. s9To set a user password use "configured_password" instead.tchangedtwarningstadminRBN(R/Ri(R>R=R;(RltTrueRRRRCRRR?R@R0RRqR^RDRwRYt
differenceRt
check_modeR
t	exit_json(thashed_password_spectelement_spectaggregate_specR`R�RR�tresultR+R,RBR-t
want_userst
have_usersR5((sH/usr/lib/python2.7/site-packages/ansible/modules/network/ios/ios_user.pytmain�sd	
'

		




	
t__main__(%tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLEStRETURNR RREtcopyRt	functoolsRtansible.module_utils.basicRt)ansible.module_utils.network.common.utilsRt$ansible.module_utils.network.ios.iosR	R
RRtansible.module_utils.sixR
RRR'RDRKRQRSRVR^RhRqRmRwR�t__name__(((sH/usr/lib/python2.7/site-packages/ansible/modules/network/ios/ios_user.pyt<module>s>


mN
					?							#		
	O

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]