玖叶教程网

前端编程开发入门

ansible模块之git

概要说明

ansible是一款非常强大的自动化运维工具,使我们可以很快捷地实现对远程目标服务器的自动化运维,包括服务器维护,文件操作,实时监控,项目服务更新,备份等等N多行为,就像你手工远程到服务器的一系列操作,都可以通过ansible帮你完成,而且它还是可以批量操作的。今天介绍的就是它的 git 模块,这个模块让我们很方便地管理存储库的git签出以部署文件或软件,执行此模块的主机需要满足git版本>=1.7.1。

参数说明

repo:git存储库的git、SSH或HTTP(S)协议地址

dest:签出存储库的路径,即从git仓库拉下来后,保存的路径

clone:是否克隆存储库

update:是否从存储库检索新修订

force:是否丢弃工作存储库中任何修改的文件

version:要签出的存储库版本。这可以是文字字符串头、分支名称和标记名称

更多参数请见下表

Choices:

If yes, ensure that "-o StrictHostKeyChecking=no" is present as an ssh option.

accept_hostkey

no ←


yes



archive


Specify archive file path with extension. If specified, creates an archive file of the specified format containing the tree structure for the source tree. Allowed archive formats ["zip", "tar.gz", "tar", "tgz"].


This will clone and perform git archive from local directory as not all git servers support git archive.

archive_prefix


Specify a prefix to add to each file path in archive. Requires archive to be specified.


bare

Choices:

If yes, repository will be created as a bare repo, otherwise it will be a standard repo with a workspace.


no ←


yes

clone

Choices:

If no, do not clone the repository even if it does not exist locally.


no


yes ←

depth


Create a shallow clone with a history truncated to the specified number or revisions. The minimum possible value is 1, otherwise ignored. Needs git>=1.9.1 to work correctly.


dest


The path of where the repository should be checked out. This is equivalent to git clone [repo_url] [directory]. The repository named in repo is not appended to this path and the destination directory must be empty. This parameter is required, unless clone is set to no.

executable


Path to git executable to use. If not supplied, the normal mechanism for resolving binary paths will be used.


force

Choices:

If yes, any modified files in the working repository will be discarded. Prior to 0.7, this was always 'yes' and could not be disabled. Prior to 1.9, the default was `yes`.


no ←


yes

gpg_whitelist

Default:

A list of trusted GPG fingerprints to compare to the fingerprint of the GPG-signed commit.


[]

Only used when verify_commit=yes.



Use of this feature requires Git 2.6+ due to its reliance on git's --raw flag to verify-commit and verify-tag.

key_file


Specify an optional private key file path, on the target host, to use for the checkout.


recursive

Choices:

If no, repository will be cloned without the --recursive option, skipping sub-modules.


no


yes ←

reference


Reference repository (see "git clone --reference ...").


refspec


Add an additional refspec to be fetched. If version is set to a SHA-1 not reachable from any branch or tag, this option may be necessary to specify the ref containing the SHA-1. Uses the same syntax as the git fetch command. An example value could be "refs/meta/config".


remote

Default:

Name of the remote.

repo


git, SSH, or HTTP(S) protocol address of the git repository.



separate_git_dir


The path to place the cloned repository. If specified, Git repository can be separated from working tree.


single_branch

Choices:

Clone only the history leading to the tip of the specified revision.


no ←


yes

ssh_opts


Creates a wrapper script and exports the path as GIT_SSH which git then automatically uses to override ssh arguments. An example value could be "-o StrictHostKeyChecking=no" (although this particular option is better set by accept_hostkey).


track_submodules

Choices:

If yes, submodules will track the latest commit on their master branch (or other branch specified in .gitmodules). If no, submodules will be kept at the revision specified by the main project. This is equivalent to specifying the --remote flag to git submodule update.


no ←


yes

umask


The umask to set before doing any checkouts, or any other repository maintenance.


update

Choices:

If no, do not retrieve new revisions from the origin repository.


no

Operations like archive will work on the existing (old) repository and might not respond to changes to the options version or remote.


yes ←


verify_commit

Choices:

If yes, when cloning or checking out a version verify the signature of a GPG signed commit. This requires git version>=2.1.0 to be installed. The commit MUST be signed and the public key MUST be present in the GPG keyring.


no ←


yes

version

Default:

What version of the repository to check out. This can be the literal string HEAD, a branch name, a tag name. It can also be a SHA-1 hash, in which case refspec needs to be specified if the given revision is not already available.


"HEAD"


实例说明

下面这个例子是从git上拉取仓库到 /test/member,这里的repo带了参数,是因为git不是共享的,是需要登录的,要执行这个playbook,也需要带上参数,如:

ansible-playbook test.yml -e 'githubuser=root' -e 'githubpassword=123456'


playbook如下:

- name: Get updated files from git repository

git:

repo: "http://{{ githubuser | urlencode }}:{{ githubpassword | urlencode }}@192.168.0.110/test/member.git"

dest: /test/member

clone: yes

update: yes

force: yes

version: master


发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言