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_job.pyc

�
�Udac@`s ddlmZmZmZeZidd6dgd6dd6ZdZd	Zd
Z	ddl
Z
ddljj
ZdZyddlZeZWn#ek
r�e
j�ZeZnXddlmZmZdd
lmZddd��YZd�Zd�Zd�Ze dkre�ndS(i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontpreviewtstatust	communitytsupported_bysQ
---
module: jenkins_job
short_description: Manage jenkins jobs
description:
    - Manage Jenkins jobs by using Jenkins REST API.
requirements:
  - "python-jenkins >= 0.4.12"
version_added: "2.2"
author: "Sergio Millan Rodriguez (@sermilrod)"
options:
  config:
    description:
      - config in XML format.
      - Required if job does not yet exist.
      - Mutually exclusive with C(enabled).
      - Considered if C(state=present).
    required: false
  enabled:
    description:
      - Whether the job should be enabled or disabled.
      - Mutually exclusive with C(config).
      - Considered if C(state=present).
    type: bool
    required: false
  name:
    description:
      - Name of the Jenkins job.
    required: true
  password:
    description:
      - Password to authenticate with the Jenkins server.
    required: false
  state:
    description:
      - Attribute that specifies if the job has to be created or deleted.
    required: false
    default: present
    choices: ['present', 'absent']
  token:
    description:
      - API token used to authenticate alternatively to password.
    required: false
  url:
    description:
      - URL where the Jenkins server is accessible.
    required: false
    default: http://localhost:8080
  user:
    description:
       - User to authenticate with the Jenkins server.
    required: false
sg
# Create a jenkins job using basic authentication
- jenkins_job:
    config: "{{ lookup('file', 'templates/test.xml') }}"
    name: test
    password: admin
    url: http://localhost:8080
    user: admin

# Create a jenkins job using the token
- jenkins_job:
    config: "{{ lookup('template', 'templates/test.xml.j2') }}"
    name: test
    token: asdfasfasfasdfasdfadfasfasdfasdfc
    url: http://localhost:8080
    user: admin

# Delete a jenkins job using basic authentication
- jenkins_job:
    name: test
    password: admin
    state: absent
    url: http://localhost:8080
    user: admin

# Delete a jenkins job using the token
- jenkins_job:
    name: test
    token: asdfasfasfasdfasdfadfasfasdfasdfc
    state: absent
    url: http://localhost:8080
    user: admin

# Disable a jenkins job using basic authentication
- jenkins_job:
    name: test
    password: admin
    enabled: False
    url: http://localhost:8080
    user: admin

# Disable a jenkins job using the token
- jenkins_job:
    name: test
    token: asdfasfasfasdfasdfadfasfasdfasdfc
    enabled: False
    url: http://localhost:8080
    user: admin
s
---
name:
  description: Name of the jenkins job.
  returned: success
  type: str
  sample: test-job
state:
  description: State of the jenkins job.
  returned: success
  type: str
  sample: present
enabled:
  description: Whether the jenkins job is enabled or not.
  returned: success
  type: bool
  sample: true
user:
  description: User used for authentication.
  returned: success
  type: str
  sample: admin
url:
  description: Url to connect to the Jenkins server.
  returned: success
  type: str
  sample: https://jenkins.mydomain.com
N(t
AnsibleModuletmissing_required_lib(t	to_nativet
JenkinsJobcB`s�eZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�ZRS(cC`s||_|jjd�|_|jjd�|_|jjd�|_|jjd�|_|jjd�|_|jjd�|_|jjd�|_	|jjd�|_
|j�|_it
d	6|j
d6|jd6|j	d6|jd6id
d6d
d6d
6|_d|_dS(Ntconfigtnametpasswordtstatetenabledttokentuserturltchangedttbeforetaftertdiffsexcluded state(tmoduletparamstgetRR
RRRRRtjenkins_urltget_jenkins_connectiontservertFalsetresultt
EXCL_STATE(tselfR((sR/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_job.pyt__init__�s(	



cC`s�y�|jr1|jr1tj|j|j|j�S|jr_|jr_tj|j|j|j�S|jr�|jpw|jr�tj|j|j�Stj|j�SWn<tk
r�}|jjddt	|�dt
j��nXdS(Ntmsgs'Unable to connect to Jenkins server, %st	exception(RRtjenkinstJenkinsRRt	ExceptionRt	fail_jsonR
t	tracebackt
format_exc(R"te((sR/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_job.pyR�scC`s�y=|jj|j�}d|kr+|jS|djd�SWn<tk
r{}|jjddt|�dt	j
��nXdS(Ntcolorsutf-8R$s#Unable to fetch job information, %sR%(Rtget_job_infoR
R!tencodeR(RR)R
R*R+(R"tresponseR,((sR/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_job.pytget_job_status�scC`siyt|jj|j��SWnEtk
rd}|jjddt|�|jfdt	j
��nXdS(NR$s+Unable to validate if job exists, %s for %sR%(tboolRt
job_existsR
R(RR)R
RR*R+(R"R,((sR/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_job.pyR3�s
%cC`s
t|j�S(N(tjob_config_to_stringR(R"((sR/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_job.pyt
get_config�scC`s"t|jj|j�jd��S(Nsutf-8(R4Rtget_job_configR
R/(R"((sR/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_job.pytget_current_config�scC`sa|jdkrtS|j�}|j�}||jdd<||jdd<||kr]tStS(NRRR(RtNoneRR5R7R tTrue(R"tconfig_filetmachine_file((sR/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_job.pythas_config_changed�scC`s[|jdkr4|jdkr4|jjdd�n|j�sM|j�n
|j�dS(NR$sHone of the following params is required on state=present: config,enabled(RR8RRR)R3t
create_jobt
update_job(R"((sR/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_job.pytpresent_job�s

cC`sQ|jdkrtS|jtkr.|dksI|jtkrM|dkrMtStS(Ntdisabled(RR8RR9(R"R((sR/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_job.pythas_state_changed�s
6cC`s<|jtkr%|jj|j�n|jj|j�dS(N(RRRtdisable_jobR
t
enable_job(R"((sR/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_job.pytswitch_statescC`s�y�|j�}|j�rVt|jd<|jjs�|jj|j|j	��q�nG||j
kr�|j|�r�t|jd<|jjs�|j�q�nWnEt
k
r�}|jjddt|�|jfdtj��nXdS(NRR$s$Unable to reconfigure job, %s for %sR%(R1R<R9R Rt
check_modeRtreconfig_jobR
R5R!RARDR(R)R
RR*R+(R"RR,((sR/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_job.pyR>s
"
%cC`s�|jdkr%|jjdd�nt|jd<yF|j�}||jdd<|jjsw|jj	|j
|�nWnEtk
r�}|jjddt|�|j
fdtj��nXdS(NR$smissing required param: configRRRsUnable to create job, %s for %sR%(RR8RR)R9R R5RERR=R
R(R
RR*R+(R"R:R,((sR/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_job.pyR= s
%cC`s�|j�r�t|jd<|j�|jdd<|jjs�y|jj|j�Wq�t	k
r�}|jj
ddt|�|jfdt
j��q�Xq�ndS(NRRRR$sUnable to delete job, %s for %sR%(R3R9R R7RRERt
delete_jobR
R(R)R
RR*R+(R"R,((sR/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_job.pyt
absent_job.s
%cC`s<|j}|j�r.|j�dk|d<n
d|d<|S(NR@R(R R3R1R8(R"R ((sR/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_job.pyt
get_result9s
	
(t__name__t
__module__R#RR1R3R5R7R<R?RARDR>R=RHRI(((sR/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_job.pyR�s		
													cC`s/ts+|jdtddd�dt�ndS(NR$spython-jenkinsRs<https://python-jenkins.readthedocs.io/en/latest/install.htmlR%(tpython_jenkins_installedR)R	tJENKINS_IMP_ERR(R((sR/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_job.pyttest_dependenciesBs
			cC`stjtj|��jd�S(Ntascii(tETttostringt
fromstringtdecode(txml_str((sR/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_job.pyR4JscC`s4tdtdtdt�dtdt�dtdtdt�dtdtdd	d
gdd	�dtdtd
d�dtdtdt�dtdtdd�dtdt��dddgddggdt�}t|�t|�}|jjd�d	kr
|j�n
|j	�|j
�}|j|�dS(Nt
argument_specRtrequiredR
Rtno_logRtchoicestpresenttabsenttdefaultRttypeR2RRshttp://localhost:8080Rtmutually_exclusivetsupports_check_mode(RtdictRR9RNRRRR?RHRIt	exit_json(Rtjenkins_jobR ((sR/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_job.pytmainNs(!		


t__main__((!t
__future__RRRR\t
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLEStRETURNR*txml.etree.ElementTreetetreetElementTreeRPR8RMR&R9RLtImportErrorR+Rtansible.module_utils.basicRR	tansible.module_utils._textR
RRNR4RbRJ(((sR/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_job.pyt<module>s0


72


�			

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