Anons79 Mini Shell

Directory : /lib/python2.7/site-packages/ansible/modules/web_infrastructure/
Upload File :
Current File : //lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_plugin.pyo

�
�Udac@`s;ddlmZmZmZeZidd6dgd6dd6ZdZd	Zd
Z	ddl
mZmZddl
mZdd
lmZddlmZmZddlmZmZmZddlZddlZddlZddlZddlZddlZdefd��YZ d�Z!e"dkr7e!�ndS(i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontpreviewtstatust	communitytsupported_bys-

---
module: jenkins_plugin
author: Jiri Tyr (@jtyr)
version_added: '2.2'
short_description: Add or remove Jenkins plugin
description:
  - Ansible module which helps to manage Jenkins plugins.

options:
  group:
    description:
      - Name of the Jenkins group on the OS.
    default: jenkins
  jenkins_home:
    description:
      - Home directory of the Jenkins user.
    default: /var/lib/jenkins
  mode:
    description:
      - File mode applied on versioned plugins.
    default: '0644'
  name:
    description:
      - Plugin name.
    required: yes
  owner:
    description:
      - Name of the Jenkins user on the OS.
    default: jenkins
  state:
    description:
      - Desired plugin state.
      - If the C(latest) is set, the check for new version will be performed
        every time. This is suitable to keep the plugin up-to-date.
    choices: [absent, present, pinned, unpinned, enabled, disabled, latest]
    default: present
  timeout:
    description:
      - Server connection timeout in secs.
    default: 30
  updates_expiration:
    description:
      - Number of seconds after which a new copy of the I(update-center.json)
        file is downloaded. This is used to avoid the need to download the
        plugin to calculate its checksum when C(latest) is specified.
      - Set it to C(0) if no cache file should be used. In that case, the
        plugin file will always be downloaded to calculate its checksum when
        C(latest) is specified.
    default: 86400
  updates_url:
    description:
      - URL of the Update Centre.
      - Used as the base URL to download the plugins and the
        I(update-center.json) JSON file.
    default: https://updates.jenkins.io
  url:
    description:
      - URL of the Jenkins server.
    default: http://localhost:8080
  version:
    description:
      - Plugin version number.
      - If this option is specified, all plugin dependencies must be installed
        manually.
      - It might take longer to verify that the correct version is installed.
        This is especially true if a specific version number is specified.
      - Quote the version to prevent the value to be interpreted as float. For
        example if C(1.20) would be unquoted, it would become C(1.2).
  with_dependencies:
    description:
      - Defines whether to install plugin dependencies.
      - This option takes effect only if the I(version) is not defined.
    type: bool
    default: yes

notes:
  - Plugin installation should be run under root or the same user which owns
    the plugin files on the disk. Only if the plugin is not installed yet and
    no version is specified, the API installation is performed which requires
    only the Web UI credentials.
  - It's necessary to notify the handler or call the I(service) module to
    restart the Jenkins service after a new plugin was installed.
  - Pinning works only if the plugin is installed and Jenkins service was
    successfully restarted after the plugin installation.
  - It is not possible to run the module remotely by changing the I(url)
    parameter to point to the Jenkins server. The module must be used on the
    host where Jenkins runs as it needs direct access to the plugin files.
  - "The C(params) option was removed in Ansible 2.5 due to circumventing Ansible's
    option handling"
extends_documentation_fragment:
  - url
s�

- name: Install plugin
  jenkins_plugin:
    name: build-pipeline-plugin

- name: Install plugin without its dependencies
  jenkins_plugin:
    name: build-pipeline-plugin
    with_dependencies: no

- name: Make sure the plugin is always up-to-date
  jenkins_plugin:
    name: token-macro
    state: latest

- name: Install specific version of the plugin
  jenkins_plugin:
    name: token-macro
    version: "1.15"

- name: Pin the plugin
  jenkins_plugin:
    name: token-macro
    state: pinned

- name: Unpin the plugin
  jenkins_plugin:
    name: token-macro
    state: unpinned

- name: Enable the plugin
  jenkins_plugin:
    name: token-macro
    state: enabled

- name: Disable the plugin
  jenkins_plugin:
    name: token-macro
    state: disabled

- name: Uninstall plugin
  jenkins_plugin:
    name: build-pipeline-plugin
    state: absent

#
# Example of how to authenticate
#
- name: Install plugin
  jenkins_plugin:
    name: build-pipeline-plugin
    url_username: admin
    url_password: p4ssw0rd
    url: http://localhost:8888

#
# Example of a Play which handles Jenkins restarts during the state changes
#
- name: Jenkins Master play
  hosts: jenkins-master
  vars:
    my_jenkins_plugins:
      token-macro:
        enabled: yes
      build-pipeline-plugin:
        version: "1.4.9"
        pinned: no
        enabled: yes
  tasks:
    - name: Install plugins without a specific version
      jenkins_plugin:
        name: "{{ item.key }}"
      register: my_jenkins_plugin_unversioned
      when: >
        'version' not in item.value
      with_dict: "{{ my_jenkins_plugins }}"

    - name: Install plugins with a specific version
      jenkins_plugin:
        name: "{{ item.key }}"
        version: "{{ item.value['version'] }}"
      register: my_jenkins_plugin_versioned
      when: >
        'version' in item.value
      with_dict: "{{ my_jenkins_plugins }}"

    - name: Initiate the fact
      set_fact:
        jenkins_restart_required: no

    - name: Check if restart is required by any of the versioned plugins
      set_fact:
        jenkins_restart_required: yes
      when: item.changed
      with_items: "{{ my_jenkins_plugin_versioned.results }}"

    - name: Check if restart is required by any of the unversioned plugins
      set_fact:
        jenkins_restart_required: yes
      when: item.changed
      with_items: "{{ my_jenkins_plugin_unversioned.results }}"

    - name: Restart Jenkins if required
      service:
        name: jenkins
        state: restarted
      when: jenkins_restart_required

    - name: Wait for Jenkins to start up
      uri:
        url: http://localhost:8080
        status_code: 200
        timeout: 5
      register: jenkins_service_status
      # Keep trying for 5 mins in 5 sec intervals
      retries: 60
      delay: 5
      until: >
         'status' in jenkins_service_status and
         jenkins_service_status['status'] == 200
      when: jenkins_restart_required

    - name: Reset the fact
      set_fact:
        jenkins_restart_required: no
      when: jenkins_restart_required

    - name: Plugin pinning
      jenkins_plugin:
        name: "{{ item.key }}"
        state: "{{ 'pinned' if item.value['pinned'] else 'unpinned'}}"
      when: >
        'pinned' in item.value
      with_dict: "{{ my_jenkins_plugins }}"

    - name: Plugin enabling
      jenkins_plugin:
        name: "{{ item.key }}"
        state: "{{ 'enabled' if item.value['enabled'] else 'disabled'}}"
      when: >
        'enabled' in item.value
      with_dict: "{{ my_jenkins_plugins }}"
s�
plugin:
    description: plugin name
    returned: success
    type: str
    sample: build-pipeline-plugin
state:
    description: state of the target, after execution
    returned: success
    type: str
    sample: "present"
(t
AnsibleModuletto_bytes(thttp_cookiejar(t	urlencode(t	fetch_urlturl_argument_spec(t	to_nativet	text_typetbinary_typeNt
JenkinsPlugincB`s�eZd�Zd�Zd�Zdddd�Zd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zd�Zd
�Zd�Zd�Zd�Zd�ZRS(cC`s�||_|jj|_|jd|_|jd|_i|_d|_|j�rwtj	�|_|j
�|_n|j�dS(Nturlttimeout(tmoduletparamsRRtcrumbtNonetcookiest
_csrf_enabledt	cookiejartLWPCookieJart
_get_crumbt_get_installed_plugins(tselfR((sU/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_plugin.pyt__init__s			cC`sO|jd|jdfd�}d|krG|jjddd|�n|dS(Ns%s/%ssapi/jsontCSRFt	useCrumbstmsgs1Required fields not found in the Crumbs response.tdetails(t_get_json_dataRRt	fail_json(Rt	csrf_data((sU/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_plugin.pyR-s
cK`sq|j|||�}ytjt|j���}Wn6tk
rl}|jjdd|dt|��nX|S(NR"sCannot parse %s JSON data.R#(t
_get_url_datatjsontloadsRtreadt	ExceptionRR%(RRtwhattkwargstrt	json_datate((sU/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_plugin.pyR$8s
c	
K`s�|dkrd|}n|dkr2d|}nyjt|j|d|jd|jd|j|�\}}|ddkr�|jjd|d	|d�nWn2tk
r�}|jjd|d	t|��nX|S(
Ns
Cannot get %ssRetrieval of %s failed.RRtheadersRi�R"R#(	RRRRRRR%R+R(	RRR,t
msg_statust
msg_exceptionR-tresponsetinfoR0((sU/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_plugin.pyR'Fs

$#cC`sl|jd|jdfd�}d|krOd|krOi|d|d6}n|jjddd|�|S(	Ns%s/%sscrumbIssuer/api/jsontCrumbtcrumbRequestFieldRR"s/Required fields not found in the Crum response.R#(R$RRR%(Rt
crumb_datatret((sU/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_plugin.pyR]scC`s�|jd|jdfd�}d|krA|jjdd�nt|_t|_t|_xb|dD]V}|d|jdkrgt	|_|d	r�t	|_n|d
r�t	|_nPqgqgWdS(Ns%s/%sspluginManager/api/json?depth=1slist of pluginstpluginsR"sNo valid plugin data found.t	shortNametnametpinnedtenabled(
R$RRR%tFalsetis_installedt	is_pinnedt
is_enabledRtTrue(Rtplugins_datatp((sU/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_plugin.pyRls 					

c
C`s"t}d|jd|jdf}|jr|jddkr|jjs	d|jd}|jdr�d|jd|f}ni|d	6}t|�}|jd
|jddd
dd|�}d|jd|jdf}t	j
j|�r	t	j|�q	nt
}n�t	j
j|jd�sA|jjdd�nd}t	j
j|�r�t|d��}	|	j�}
WdQXtj|
�j�}n|jddkr�d|jd|jdf}n*dj|jd|jd|jd�}|jddks%|jddks%|dkr�|j|�}|dkrh|jjs_|j||�nt
}q�|j�}tj|�j�}||kr�|jjs�|j||�nt
}q�n�|jddkr�|j�}
y7t|d��}|j�}WdQXtj|�}Wn2tk
rJ}|jjdddt|��nXtj|j��}|t|
d�kr�|jjs�|j|�}|j||�nt
}q�nt	j
j|�ri|d6}|j |j�|jj!|�}|jjs|jj"||�}qt
}n|S( Ns%s/plugins/%s.jpitjenkins_homeR<tversiontlatestsDd = Jenkins.instance.updateCenter.getPlugin("%s").deploy(); d.get();twith_dependenciess[Jenkins.instance.updateCenter.getPlugin("%s").getNeededDependencies().each{it.deploy()}; %stscripts
%s/scriptTextR2sCannot install plugin.R3sPlugin installation has failed.tdatas%s/plugins/%s.hpiR"s%Jenkins home directory doesn't exist.trbs%s/latest/%s.hpitupdates_urls${0}/download/plugins/{1}/{2}/{1}.hpitupdates_expirationis(Cannot calculate SHA1 of the old plugin.R#tsha1tdest(NRH(NRH(NRH(#R?RR@RRt
check_modeRR'RtostpathtisfiletremoveRCtisdirR%topenR*thashlibtmd5t	hexdigesttformatt_download_plugint_write_filet_download_updatesROR+Rtbase64t	b64encodetdigestR	tupdatetload_file_common_argumentstset_fs_attributes_if_different(Rtchangedtplugin_filetinstall_scripttscript_dataRKR.thpi_filet
md5sum_oldt
md5_plugin_fhtmd5_plugin_contentt
plugin_urlt
md5sum_newtplugin_datatsha1_plugin_fhtsha1_plugin_contenttsha1_oldR0tsha1sum_oldRt	file_args((sU/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_plugin.pytinstall�s�



	
	



	
		cC`s�d}tjjd�}d||f}t}tjj|�r�tj|�j}tj�}|||jdkr�t	}q�n|}|r.d|jd}|j
|ddd	d
�}	tj�\}
}tj
|
|	j��ytj|
�Wq.tk
r*}|jjdd|d
t|��q.Xnyt|�}Wn2tk
rr}|jjddd
t|��nXd}
xp|D]h}|
dkr�ytj|�}Wn2tk
r�}|jjddd
t|��nXPn|
d7}
q�W|rotjj|�sYytj|tdd��WqYtk
rU}|jjddd
t|��qYXn|jj||�nd|ks�|jd|dkr�|jjdd�n|d|jdS(Nsjenkins-plugin-cache.jsons~/.ansible/tmps%s/%sRNs%s/update-center.jsonRMR2sRemote updates not found.R3sUpdates download failed.R"s%Cannot close the tmp updates file %s.R#s"Cannot open temporal updates file.iis0Cannot load JSON data from the tmp updates file.t0700is!Cannot create temporal directory.R:R<s,Cannot find plugin data in the updates file.(RRRSt
expanduserRCRTtstattst_mtimettimeRR?R'ttempfiletmkstemptwriteR*tclosetIOErrorRR%RRWR(R)R+RVtmakedirstinttOSErrortatomic_move(Rtupdates_filenametupdates_dirtupdates_filetdownload_updatestts_filetts_nowtupdates_file_origRR.t	update_fdR0tftitlineRK((sU/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_plugin.pyR^sl	

#
cC`s|j|dddd�}|S(NR2sPlugin not found.R3sPlugin download failed.(R'(RRmR.((sU/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_plugin.pyR\as
	cC`s�tj�\}}t|ttf�r:tj||�ntj||j��ytj|�Wn6t	k
r�}|j
jdd|dt|��nX|j
j
||�dS(NR"s)Cannot close the temporal plugin file %s.R#(R{R|t
isinstanceRRRRR}R*R~RRR%RR�(RR�RKttmp_f_fdttmp_fR0((sU/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_plugin.pyR]js
cC`s;t}|jr7|jjs.|jdd�nt}n|S(NtdoUninstalltUninstallation(R?R@RRQt	_pm_queryRC(RRe((sU/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_plugin.pyt	uninstall}s		cC`s
|jd�S(Ntpin(t_pinning(R((sU/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_plugin.pyR��scC`s
|jd�S(Ntunpin(R�(R((sU/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_plugin.pyR��scC`sgt}|dkr|js1|dkrc|jrc|jjsZ|j|d|j��nt}n|S(NR�R�s%sning(R?RARRQR�t
capitalizeRC(RtactionRe((sU/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_plugin.pyR��s	cC`s
|jd�S(Ntenable(t	_enabling(R((sU/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_plugin.pyR��scC`s
|jd�S(Ntdisable(R�(R((sU/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_plugin.pyR��scC`sut}|dkr|js1|dkrq|jrq|jjsh|jd|j�d|d j��nt}n|S(NR�R�smake%sds%singi����(R?RBRRQR�R�RC(RR�Re((sU/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_plugin.pyR��s
	cC`sFd|jd|jd|f}|j|dd|dd|�dS(Ns%s/pluginManager/plugin/%s/%sRR<R2sPlugin not found. %sR3s%s has failed.(RR'(RR�R"R((sU/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_plugin.pyR��s
N(t__name__t
__module__RRR$RR'RRRuR^R\R]R�R�R�R�R�R�R�R�(((sU/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_plugin.pyRs$						�	Q										c!C`s�t�}|jdtdd�dtdd�dtdddd	�d
tdt�dtdd�d
tdd�dtddddddddgdd�dtdddd�dtdddd�dtdd�dtdd �d!td"t�d#t�d$tdtdd%��td&|d'td(t�}|jd
rM|jd)d*�nt|jd+<yt|jd�|jd<Wn:tk
r�}|jd)d,|jdd-t	|��nX|jddkr�d|jd<d|jd#<n|jd
}|jd}t
}t|�}|dkr,|j�}n�|dkrG|j
�}nl|dkrb|j�}nQ|dkr}|j�}n6|dkr�|j�}n|dkr�|j�}n|jd.|d/|d|�dS(0NtgrouptdefaulttjenkinsRFs/var/lib/jenkinstmodet0644ttypetrawR<trequiredtownerRtdicttstatetchoicestpresenttabsentR=tunpinnedR>tdisabledRHRiR�RNi�QRMshttps://updates.jenkins.ioRshttp://localhost:8080turl_passwordtno_logRGRItboolt
argument_spectadd_file_common_argstsupports_check_modeR"smThe params option to jenkins_plugin was removed in Ansible 2.5 since it circumvents Ansible's option handlingtforce_basic_authsCannot convert %s to float.R#Retplugin(R
RbR�RCRRR%tfloatt
ValueErrorRR?RRuR�R�R�R�R�t	exit_json(R�RR0R<R�Retjp((sU/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_plugin.pytmain�sr						

	


t__main__(#t
__future__RRRR�t
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLEStRETURNtansible.module_utils.basicRR	tansible.module_utils.six.movesR
Rt+ansible.module_utils.six.moves.urllib.parseRtansible.module_utils.urlsRR
tansible.module_utils._textRRRR_RXR(RRR{RztobjectRR�R�(((sU/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_plugin.pyt<module>s.


^�
��	T

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