deploy_helper — Управляет некоторыми шагами, общими при развертывании проектов.
Новая версия с 2.0.
Обзор
- Модуль Deploy Helper управляет некоторыми шагами, общими при развертывании программного обеспечения. Он создает структуру папок, управляет символьным ссылкой для текущей версии и очищает старые версии.
- Запуск с
state=queryилиstate=presentвернёт фактdeploy_helper.project_path, значение, которое вы задали в параметре path,current_path, путь к симлинку, указывающему на активную версию,releases_path, путь к папке для хранения версий,shared_path, путь к папке для хранения общих ресурсов,unfinished_filename, файл для проверки, чтобы распознать незавершенные сборки,previous_release, версия, на которую указывает симлинк ‘current’,previous_release_path, полный путь к целевому файлу симлинка ‘current’,new_release, либо параметр ‘release’, либо сгенерированный временной отметкой,new_release_path, путь к новой папке версии (не созданной модулем).
Параметры
| Параметр | Варианты/Значения по умолчанию | Комментарии |
|---|---|---|
| clean bool |
| Выполнить ли процедуру очистки в случае state=finalize. |
| current_path | Значение по умолчанию: "current" | имя симлинка, создаваемого при завершении развертывания. Используется в finalize и clean. Возвращается в факте deploy_helper.current_path. |
| keep_releases | Значение по умолчанию: 5 | количество старых версий для сохранения при очистке. Используется в finalize и clean. Любые незавершенные сборки будут удалены в первую очередь, поэтому будут учитываться только правильные версии. Текущая версия не учитывается. |
| path обязательный | корневой путь проекта. Псевдоним dest. Возвращается в факте deploy_helper.project_path.псевдонимы: dest | |
| release | версия выпуска, которая развертывается. По умолчанию используется формат временной метки %Y%m%d%H%M%S (например, '20141119223359'). Этот параметр является необязательным при state=present, но должен быть задан явно для state=finalize. Вы можете использовать сгенерированный факт release={{ deploy_helper.new_release }}. | |
| releases_path | Значение по умолчанию: "releases" | имя папки, которая будет содержать версии. Может быть относительным к path или абсолютным. Возвращается в факте deploy_helper.releases_path. |
| shared_path | Значение по умолчанию: "shared" | имя папки, которая будет содержать общие ресурсы. Может быть относительным к path или абсолютным. Если значение установлено на пустую строку, папка shared не будет создана. Возвращается в факте deploy_helper.shared_path. |
| state |
| состояние проекта. query будет только собирать факты, present создаст корневую папку проекта, а в ней папки releases и shared, finalize удалит файл unfinished_filename, создаст символьную ссылку на недавно развернутую версию и при необходимости очистит старые версии, clean удалит неудачные и старые версии, absent удалит папку проекта (аналогично модулю file с state=absent). |
| unfinished_filename | Значение по умолчанию: "DEPLOY_UNFINISHED" | имя файла, указывающего на то, что развертывание не завершено. Все папки в releases_path, содержащие этот файл, будут удалены при state=finalize с clean=True или state=clean. Этот файл автоматически удаляется из new_release_path во время state=finalize. |
Примечания
Примечание
- Факты возвращаются только для
state=queryиstate=present. Если вы используете оба, вы должны передать любые измененные параметры обоим вызовам, иначе второй вызов перепишет факты первого. - При использовании
state=clean, версии упорядочиваются по дате создания. Вы должны иметь возможность переключаться на новую стратегию именования без проблем. - Из-за поведения по умолчанию при генерации факта new_release, этот модуль не будет идемпотентным, если вы не передадите собственное имя версии с
release. Из-за особенностей развертывания программного обеспечения, это не должно быть большой проблемой.
Примеры
# 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
Статус
Этот модуль помечен как preview, что означает, что его интерфейс не гарантируется обратно совместимым.
Техническое обслуживание
Этот модуль помечен как community, что означает, что он поддерживается сообществом Ansible. См. Техническое обслуживание и поддержка модулей для получения дополнительной информации.
Список других модулей, также поддерживаемых сообществом Ansible, см. здесь.
Автор
- Ramon de la Fuente (@ramondelafuente)
Подсказка
Если вы обнаружите какие-либо проблемы в этой документации, вы можете изменить этот документ, чтобы улучшить его.
© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.6/modules/deploy_helper_module.html