ansible / ansible.builtin / v2.16.5 / module / git Deploy software (or files) from git checkouts | "added in version" 0.0.1 of ansible.builtin" Authors: Ansible Core Team, Michael DeHaanansible.builtin.git (v2.16.5) — module
pip
Install with pip install ansible-core==2.16.5
Manage I(git) checkouts of repositories to deploy files or software.
- name: Git checkout ansible.builtin.git: repo: 'https://foosball.example.org/path/to/repo.git' dest: /srv/checkout version: release-0.22
- name: Read-write git checkout from github ansible.builtin.git: repo: git@github.com:mylogin/hello.git dest: /home/mylogin/hello
- name: Just ensuring the repo checkout exists ansible.builtin.git: repo: 'https://foosball.example.org/path/to/repo.git' dest: /srv/checkout update: no
- name: Just get information about the repository whether or not it has already been cloned locally ansible.builtin.git: repo: 'https://foosball.example.org/path/to/repo.git' dest: /srv/checkout clone: no update: no
- name: Checkout a github repo and use refspec to fetch all pull requests ansible.builtin.git: repo: https://github.com/ansible/ansible-examples.git dest: /src/ansible-examples refspec: '+refs/pull/*:refs/heads/*'
- name: Create git archive from repo ansible.builtin.git: repo: https://github.com/ansible/ansible-examples.git dest: /src/ansible-examples archive: /tmp/ansible-examples.zip
- name: Clone a repo with separate git directory ansible.builtin.git: repo: https://github.com/ansible/ansible-examples.git dest: /src/ansible-examples separate_git_dir: /src/ansible-examples.git
- name: Example clone of a single branch ansible.builtin.git: repo: https://github.com/ansible/ansible-examples.git dest: /src/ansible-examples single_branch: yes version: master
- name: Avoid hanging when http(s) password is missing ansible.builtin.git: repo: https://github.com/ansible/could-be-a-private-repo dest: /src/from-private-repo environment: GIT_TERMINAL_PROMPT: 0 # reports "terminal prompts disabled" on missing password
bare: default: 'no' description: - If V(true), repository will be created as a bare repo, otherwise it will be a standard repo with a workspace. type: bool version_added: '1.4' version_added_collection: ansible.builtin dest: description: - The path of where the repository should be checked out. This is equivalent to C(git clone [repo_url] [directory]). The repository named in O(repo) is not appended to this path and the destination directory must be empty. This parameter is required, unless O(clone) is set to V(false). required: true type: path repo: aliases: - name description: - git, SSH, or HTTP(S) protocol address of the git repository. required: true type: str clone: default: 'yes' description: - If V(false), do not clone the repository even if it does not exist locally. type: bool version_added: '1.9' version_added_collection: ansible.builtin depth: description: - Create a shallow clone with a history truncated to the specified number or revisions. The minimum possible value is V(1), otherwise ignored. Needs I(git>=1.9.1) to work correctly. type: int version_added: '1.2' version_added_collection: ansible.builtin force: default: 'no' description: - If V(true), any modified files in the working repository will be discarded. Prior to 0.7, this was always V(true) and could not be disabled. Prior to 1.9, the default was V(true). type: bool version_added: '0.7' version_added_collection: ansible.builtin umask: description: - The umask to set before doing any checkouts, or any other repository maintenance. type: raw version_added: '2.2' version_added_collection: ansible.builtin remote: default: origin description: - Name of the remote. type: str update: default: 'yes' description: - If V(false), do not retrieve new revisions from the origin repository. - Operations like archive will work on the existing (old) repository and might not respond to changes to the options version or remote. type: bool version_added: '1.2' version_added_collection: ansible.builtin archive: description: - 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. type: path version_added: '2.4' version_added_collection: ansible.builtin refspec: description: - Add an additional refspec to be fetched. If version is set to a I(SHA-1) not reachable from any branch or tag, this option may be necessary to specify the ref containing the I(SHA-1). Uses the same syntax as the C(git fetch) command. An example value could be "refs/meta/config". type: str version_added: '1.9' version_added_collection: ansible.builtin version: default: HEAD description: - What version of the repository to check out. This can be the literal string V(HEAD), a branch name, a tag name. It can also be a I(SHA-1) hash, in which case O(refspec) needs to be specified if the given revision is not already available. type: str key_file: description: - Specify an optional private key file path, on the target host, to use for the checkout. - This ensures 'IdentitiesOnly=yes' is present in O(ssh_opts). type: path version_added: '1.5' version_added_collection: ansible.builtin ssh_opts: description: - Options git will pass to ssh when used as protocol, it works via C(git)'s E(GIT_SSH)/E(GIT_SSH_COMMAND) environment variables. - For older versions it appends E(GIT_SSH_OPTS) (specific to this module) to the variables above or via a wrapper script. - Other options can add to this list, like O(key_file) and O(accept_hostkey). - An example value could be "-o StrictHostKeyChecking=no" (although this particular option is better set by O(accept_hostkey)). - The module ensures that 'BatchMode=yes' is always present to avoid prompts. type: str version_added: '1.5' version_added_collection: ansible.builtin recursive: default: 'yes' description: - If V(false), repository will be cloned without the C(--recursive) option, skipping sub-modules. type: bool version_added: '1.6' version_added_collection: ansible.builtin reference: description: - Reference repository (see "git clone --reference ..."). type: str version_added: '1.4' version_added_collection: ansible.builtin executable: description: - Path to git executable to use. If not supplied, the normal mechanism for resolving binary paths will be used. type: path version_added: '1.4' version_added_collection: ansible.builtin gpg_whitelist: default: [] description: - A list of trusted GPG fingerprints to compare to the fingerprint of the GPG-signed commit. - Only used when O(verify_commit=yes). - Use of this feature requires Git 2.6+ due to its reliance on git's C(--raw) flag to C(verify-commit) and C(verify-tag). elements: str type: list version_added: '2.9' version_added_collection: ansible.builtin single_branch: default: 'no' description: - Clone only the history leading to the tip of the specified revision. type: bool version_added: '2.11' version_added_collection: ansible.builtin verify_commit: default: 'no' description: - If V(true), when cloning or checking out a O(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. type: bool version_added: '2.0' version_added_collection: ansible.builtin accept_hostkey: default: 'no' description: - Will ensure or not that "-o StrictHostKeyChecking=no" is present as an ssh option. - Be aware that this disables a protection against MITM attacks. - Those using OpenSSH >= 7.5 might want to set O(ssh_opts) to V(StrictHostKeyChecking=accept-new) instead, it does not remove the MITM issue but it does restrict it to the first attempt. type: bool version_added: '1.5' version_added_collection: ansible.builtin archive_prefix: description: - Specify a prefix to add to each file path in archive. Requires O(archive) to be specified. type: str version_added: '2.10' version_added_collection: ansible.builtin separate_git_dir: description: - The path to place the cloned repository. If specified, Git repository can be separated from working tree. type: path version_added: '2.7' version_added_collection: ansible.builtin track_submodules: default: 'no' description: - If V(true), submodules will track the latest commit on their master branch (or other branch specified in .gitmodules). If V(false), submodules will be kept at the revision specified by the main project. This is equivalent to specifying the C(--remote) flag to git submodule update. type: bool version_added: '1.8' version_added_collection: ansible.builtin accept_newhostkey: default: 'no' description: - As of OpenSSH 7.5, "-o StrictHostKeyChecking=accept-new" can be used which is safer and will only accepts host keys which are not present or are the same. if V(true), ensure that "-o StrictHostKeyChecking=accept-new" is present as an ssh option. type: bool version_added: '2.12' version_added_collection: ansible.builtin
after: description: Last commit revision of the repository retrieved during the update. returned: success sample: 4c020102a9cd6fe908c9a4a326a38f972f63a903 type: str before: description: Commit revision before the repository was updated, "null" for new repository. returned: success sample: 67c04ebe40a003bda0efb34eacfb93b0cafdf628 type: str git_dir_before: description: Contains the original path of .git directory if it is changed. returned: success sample: /path/to/old/git/dir type: str git_dir_now: description: Contains the new path of .git directory if it is changed. returned: success sample: /path/to/new/git/dir type: str remote_url_changed: description: Contains True or False whether or not the remote URL was changed. returned: success sample: true type: bool warnings: description: List of warnings if requested features were not available due to a too old git version. returned: error sample: git version is too old to fully support the depth argument. Falling back to full checkouts. type: str