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/deploy_helper.pyc

�
�Udac@`s�ddlmZmZmZeZidd6dgd6dd6ZdZd	Zdd
l	Z	dd
l
Z
dd
lZdd
lZddl
mZddlmZd
efd��YZd�Zedkr�e�nd
S(i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontpreviewtstatust	communitytsupported_bys_
---
module: deploy_helper
version_added: "2.0"
author: "Ramon de la Fuente (@ramondelafuente)"
short_description: Manages some of the steps common in deploying projects.
description:
  - The Deploy Helper manages some of the steps common in deploying software.
    It creates a folder structure, manages a symlink for the current release
    and cleans up old releases.
  - "Running it with the C(state=query) or C(state=present) will return the C(deploy_helper) fact.
    C(project_path), whatever you set in the path parameter,
    C(current_path), the path to the symlink that points to the active release,
    C(releases_path), the path to the folder to keep releases in,
    C(shared_path), the path to the folder to keep shared resources in,
    C(unfinished_filename), the file to check for to recognize unfinished builds,
    C(previous_release), the release the 'current' symlink is pointing to,
    C(previous_release_path), the full path to the 'current' symlink target,
    C(new_release), either the 'release' parameter or a generated timestamp,
    C(new_release_path), the path to the new release folder (not created by the module)."

options:
  path:
    required: True
    aliases: ['dest']
    description:
      - the root path of the project. Alias I(dest).
        Returned in the C(deploy_helper.project_path) fact.

  state:
    description:
      - the state of the project.
        C(query) will only gather facts,
        C(present) will create the project I(root) folder, and in it the I(releases) and I(shared) folders,
        C(finalize) will remove the unfinished_filename file, create a symlink to the newly
          deployed release and optionally clean old releases,
        C(clean) will remove failed & old releases,
        C(absent) will remove the project folder (synonymous to the M(file) module with C(state=absent))
    choices: [ present, finalize, absent, clean, query ]
    default: present

  release:
    description:
      - the release version that is being deployed. Defaults to a timestamp format %Y%m%d%H%M%S (i.e. '20141119223359').
        This parameter is optional during C(state=present), but needs to be set explicitly for C(state=finalize).
        You can use the generated fact C(release={{ deploy_helper.new_release }}).

  releases_path:
    description:
      - the name of the folder that will hold the releases. This can be relative to C(path) or absolute.
        Returned in the C(deploy_helper.releases_path) fact.
    default: releases

  shared_path:
    description:
      - the name of the folder that will hold the shared resources. This can be relative to C(path) or absolute.
        If this is set to an empty string, no shared folder will be created.
        Returned in the C(deploy_helper.shared_path) fact.
    default: shared

  current_path:
    description:
      - the name of the symlink that is created when the deploy is finalized. Used in C(finalize) and C(clean).
        Returned in the C(deploy_helper.current_path) fact.
    default: current

  unfinished_filename:
    description:
      - the name of the file that indicates a deploy has not finished. All folders in the releases_path that
        contain this file will be deleted on C(state=finalize) with clean=True, or C(state=clean). This file is
        automatically deleted from the I(new_release_path) during C(state=finalize).
    default: DEPLOY_UNFINISHED

  clean:
    description:
      - Whether to run the clean procedure in case of C(state=finalize).
    type: bool
    default: 'yes'

  keep_releases:
    description:
      - the number of old releases to keep when cleaning. Used in C(finalize) and C(clean). Any unfinished builds
        will be deleted first, so only correct releases will count. The current version will not count.
    default: 5

notes:
  - Facts are only returned for C(state=query) and C(state=present). If you use both, you should pass any overridden
    parameters to both calls, otherwise the second call will overwrite the facts of the first one.
  - When using C(state=clean), the releases are ordered by I(creation date). You should be able to switch to a
    new naming strategy without problems.
  - Because of the default behaviour of generating the I(new_release) fact, this module will not be idempotent
    unless you pass your own release name with C(release). Due to the nature of deploying software, this should not
    be much of a problem.
s�

# General explanation, starting with an example folder structure for a project:

# root:
#     releases:
#         - 20140415234508
#         - 20140415235146
#         - 20140416082818
#
#     shared:
#         - sessions
#         - uploads
#
#     current: releases/20140416082818


# The 'releases' folder holds all the available releases. A release is a complete build of the application being
# deployed. This can be a clone of a repository for example, or a sync of a local folder on your filesystem.
# Having timestamped folders is one way of having distinct releases, but you could choose your own strategy like
# git tags or commit hashes.
#
# During a deploy, a new folder should be created in the releases folder and any build steps required should be
# performed. Once the new build is ready, the deploy procedure is 'finalized' by replacing the 'current' symlink
# with a link to this build.
#
# The 'shared' folder holds any resource that is shared between releases. Examples of this are web-server
# session files, or files uploaded by users of your application. It's quite common to have symlinks from a release
# folder pointing to a shared/subfolder, and creating these links would be automated as part of the build steps.
#
# The 'current' symlink points to one of the releases. Probably the latest one, unless a deploy is in progress.
# The web-server's root for the project will go through this symlink, so the 'downtime' when switching to a new
# release is reduced to the time it takes to switch the link.
#
# To distinguish between successful builds and unfinished ones, a file can be placed in the folder of the release
# that is currently in progress. The existence of this file will mark it as unfinished, and allow an automated
# procedure to remove it during cleanup.


# Typical usage
- name: Initialize the deploy root and gather facts
  deploy_helper:
    path: /path/to/root
- name: Clone the project to the new release folder
  git:
    repo: git://foosball.example.org/path/to/repo.git
    dest: '{{ deploy_helper.new_release_path }}'
    version: v1.1.1
- name: Add an unfinished file, to allow cleanup on successful finalize
  file:
    path: '{{ deploy_helper.new_release_path }}/{{ deploy_helper.unfinished_filename }}'
    state: touch
- name: Perform some build steps, like running your dependency manager for example
  composer:
    command: install
    working_dir: '{{ deploy_helper.new_release_path }}'
- name: Create some folders in the shared folder
  file:
    path: '{{ deploy_helper.shared_path }}/{{ item }}'
    state: directory
  with_items:
    - sessions
    - uploads
- name: Add symlinks from the new release to the shared folder
  file:
    path: '{{ deploy_helper.new_release_path }}/{{ item.path }}'
    src: '{{ deploy_helper.shared_path }}/{{ item.src }}'
    state: link
  with_items:
      - path: app/sessions
        src: sessions
      - path: web/uploads
        src: uploads
- name: Finalize the deploy, removing the unfinished file and switching the symlink
  deploy_helper:
    path: /path/to/root
    release: '{{ deploy_helper.new_release }}'
    state: finalize

# Retrieving facts before running a deploy
- name: Run 'state=query' to gather facts without changing anything
  deploy_helper:
    path: /path/to/root
    state: query
# Remember to set the 'release' parameter when you actually call 'state=present' later
- name: Initialize the deploy root
  deploy_helper:
    path: /path/to/root
    release: '{{ deploy_helper.new_release }}'
    state: present

# all paths can be absolute or relative (to the 'path' parameter)
- deploy_helper:
    path: /path/to/root
    releases_path: /var/www/project/releases
    shared_path: /var/www/shared
    current_path: /var/www/active

# Using your own naming strategy for releases (a version tag in this case):
- deploy_helper:
    path: /path/to/root
    release: v1.1.1
    state: present
- deploy_helper:
    path: /path/to/root
    release: '{{ deploy_helper.new_release }}'
    state: finalize

# Using a different unfinished_filename:
- deploy_helper:
    path: /path/to/root
    unfinished_filename: README.md
    release: '{{ deploy_helper.new_release }}'
    state: finalize

# Postponing the cleanup of older builds:
- deploy_helper:
    path: /path/to/root
    release: '{{ deploy_helper.new_release }}'
    state: finalize
    clean: False
- deploy_helper:
    path: /path/to/root
    state: clean
# Or running the cleanup ahead of the new deploy
- deploy_helper:
    path: /path/to/root
    state: clean
- deploy_helper:
    path: /path/to/root
    state: present

# Keeping more old releases:
- deploy_helper:
    path: /path/to/root
    release: '{{ deploy_helper.new_release }}'
    state: finalize
    keep_releases: 10
# Or, if you use 'clean=false' on finalize:
- deploy_helper:
    path: /path/to/root
    state: clean
    keep_releases: 10

# Removing the entire project root folder
- deploy_helper:
    path: /path/to/root
    state: absent

# Debugging the facts returned by the module
- deploy_helper:
    path: /path/to/root
- debug:
    var: deploy_helper
N(t
AnsibleModule(t	to_nativetDeployHelpercB`steZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
RS(cC`s�||_|j|j�|_|jd|_|jd|_|jd|_|jd|_|jd|_|jd|_	|jd|_
|jd|_|jd	|_dS(
Ntcleantcurrent_patht
keep_releasestpathtreleaset
releases_pathtshared_pathtstatetunfinished_filename(
tmoduletload_file_common_argumentstparamst	file_argsRRR
RRRRRR(tselfR((sT/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/deploy_helper.pyt__init__s	cC`s+tjj|j|j�}tjj|j|j�}|jr]tjj|j|j�}nd}|j|�\}}|jr�|j	dks�|j	dkr�t
jd�|_n|jr�tjj||j�}nd}i	|jd6|d6|d6|d6|d6|d	6|jd
6|d6|jd6S(
Ntquerytpresents%Y%m%d%H%M%Stproject_pathRRRtprevious_releasetprevious_release_pathtnew_releasetnew_release_pathR(
tosRtjoinRRRtNonet_get_last_releaseRRttimetstrftimeR(RRRRRRR ((sT/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/deploy_helper.pytgather_facts%s*	(	

cC`s�tjj|�stStjj|�sB|jjdd|�n|jjs�ytj	|dt�Wq�t
k
r�}|jjddt|�dtj
��q�XntS(Ntmsgs %s exists but is not a directoryt
ignore_errorssrmtree failed: %st	exception(R!RtlexiststFalsetisdirRt	fail_jsont
check_modetshutiltrmtreet	ExceptionR	t	tracebackt
format_exctTrue(RRte((sT/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/deploy_helper.pytdelete_pathCs0cC`s�t}tjj|�s=t}|jjsitj|�qin,tjj|�si|jj	dd|�n||jj
|j|�|�7}|S(NR(s %s exists but is not a directory(R,R!RR+R5RR/tmakedirsR-R.t%set_directory_attributes_if_differentt_get_file_args(RRtchanged((sT/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/deploy_helper.pytcreate_pathRs"cC`sEtjj|�rAtjj|�sA|jjdd|�qAndS(NR(s$%s exists but is not a symbolic link(R!RR+tislinkRR.(RR((sT/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/deploy_helper.pyt
check_linkascC`s)t}tjj|�rtjjtjj|��}tjjtjj|��}||krit}q%t}|jjs%tjj	|�s�|jj
dd|�n|d|j}tjj|�r�tj|�ntj
||�tj||�q%n%t}|jjs%tj
||�n|S(NR(s$the symlink target %s doesn't existst.(R,R!RR=tnormpathtrealpathR5RR/R+R.Rtunlinktsymlinktrename(Rtsourcet	link_nameR;t	norm_linktnorm_sourcet
tmp_link_name((sT/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/deploy_helper.pytcreate_linkfs&	cC`sYt}tjj||j�}tjj|�rUt}|jjsUtj	|�qUn|S(N(
R,R!RR"RR+R5RR/tremove(RR R;tunfinished_file_path((sT/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/deploy_helper.pytremove_unfinished_filescC`s�d}x|tj|�D]k}tjjtjj|||j��r|jjr\|d7}q�||jtjj||��7}qqW|S(Nii(	R!tlistdirRtisfileR"RRR/R7(RRtchangesR((sT/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/deploy_helper.pytremove_unfinished_builds�s'
)cC`sbt}tjj||jd|j�}|jjr^tjj|�r^t	}tj
|�n|S(NR?(R,R!RR"RRRR/texistsR5RK(RRR;RI((sT/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/deploy_helper.pytremove_unfinished_link�s#c`sd}tjj��rgtj��D]-}tjjtjj�|��r(|^q(}y|j|�Wntk
rnX|jj	s�|j
d�fd�dt�xi||jD](}||j
tjj�|��7}q�Wqt|�|jkr|t|�|j7}qn|S(Nitkeyc`stjjtjj�|��S(N(R!RtgetctimeR"(tx(R(sT/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/deploy_helper.pyt<lambda>�streverse(R!RR+RNR-R"RKt
ValueErrorRR/tsortR5R
R7tlen(RRtreserve_versionRPtftreleasesR((RsT/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/deploy_helper.pytcleanup�sC
)cC`s|jj�}||d<|S(NR(Rtcopy(RRR((sT/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/deploy_helper.pyR:�s
cC`sOd}d}tjj|�rEtjj|�}tjj|�}n||fS(N(R#R!RR+RAtbasename(RRRR((sT/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/deploy_helper.pyR$�s(t__name__t
__module__RR'R7R<R>RJRMRQRSR_R:R$(((sT/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/deploy_helper.pyR
s							
		
		cC`s�tdtdtddgdtdd�dtdtddd	d�d
tdtddd	d�dtdtddd	d
�dtdtddd	d�dtdtddd	d�dtdtddd	t�dtdtddd	d�dtdtddddddgd	d��	dtdt�}t|�}|j�}i|jd6}d}|jdkrti|d 6|d!<n�|jdkr�|j|d�||j	|d"�7}||j	|d
�7}|j
r�||j	|d�7}ni|d 6|d!<nu|jdkr�|js$|jd#d$�n|j
dkrF|jd#d%�n||j|d&�7}||j|d&|d�7}|jrn||j|d"�7}||j|d
�7}||j|d
|d'�7}qnn�|jdkr4||j|d"�7}||j|d
�7}||j|d
|d'�7}n:|jdkrnigd 6|d!<||j|d"�7}n|dkr�t|d(<n
t|d(<|j|�dS()Nt
argument_specRtaliasestdesttrequiredttypeRtstrtdefaultRR^RtsharedRtcurrentR
tintiRtboolRtDEPLOY_UNFINISHEDRtchoicesRtabsenttfinalizeRtadd_file_common_argstsupports_check_modeit
deploy_helpert
ansible_factsRR(s_'release' is a required parameter for state=finalize (try the 'deploy_helper.new_release' fact)s$'keep_releases' should be at least 1R RR;(RtdictR5R,R#R
R'RR>R<RRR.R
RMRJRRSRQR_R7t	exit_json(RRutfactstresultRP((sT/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/deploy_helper.pytmain�sb-	
			$!

t__main__(t
__future__RRRRht
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLESR!R0R%R3tansible.module_utils.basicRtansible.module_utils._textR	tobjectR
R{Rb(((sT/usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/deploy_helper.pyt<module>	s 


`��	F

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