Ansible - git module

If you are not familiar with modules, check out Ansible - Getting Started with Modules.

The git module can be used to clone a git repository to a directory on a managed node. This is like using the git clone command. In this example, the foo.git repository is cloned to the /usr/local/git/foo directory on the managed node.

  • The GIT_TERMINAL_PROMPT variable is used to prevent this task from hanging indefinitely if the password is invalid, which would cause a terminal prompt for the password.
  • The GIT_SSL_NO_VERIFY variable is used disable SSL verfification, which can prevent stderr "peer's certificate issuer is not recognized" from being returned.
- name: clone foo.git
  git:
    repo: 'https://john.doe:itsasecret@git.example.com/foo.git'
    dest: /usr/local/git/foo
  environment:
    GIT_TERMINAL_PROMPT: false
    GIT_SSL_NO_VERIFY: true

 

branch

By default, all of the branches in the repository will be cloned. The version option is used to specify the name of a branch to clone.

- name: clone foo.git
  git:
    repo: 'https://john.doe:itsasecret@git.example.com/foo.git'
    dest: /usr/local/git/foo
    version: master
  environment:
    GIT_TERMINAL_PROMPT: false
    GIT_SSL_NO_VERIFY: true

 

zip tar gzip archive

A zip, tar, or gzip compressed tar archive of a git repository can be created. This is kind of like using the git archive command.

AVOID TROUBLE

This module requires that the repository first be cloned onto the managed node, and then an archive of the directory on the managed node is created. Which means you may need to use the file module to remove the clone directory (e.g. rmdir /usr/local/git/foo).

This module does not support creating an archive that only contains a specific file or directory in the archive.

For these reasons, it may make more sense to use the shell module with the git archive command.

In this example, the foo.tar.gz archive will be created.

- name: create foo.tar.gz of foo.git
  git:
    repo: 'https://john.doe:itsasecret@git.example.com/foo.git'
    dest: /usr/local/git/foo
    archive: /tmp/foo.tar.gz
  environment:
    GIT_TERMINAL_PROMPT: false
    GIT_SSL_NO_VERIFY: true

 

git add / git remove / git commit

The git module does not support common git tasks such as git add, git remove, and git commit. The shell module can be used to perform these other git tasks.

- name: add bar.txt to foo.git
  shell: git add bar.txt

 

AVOID TROUBLE

If "peer's certificate issuer is not recognized" is being returned, the GIT_SSL_NO_VERIFY variable can be set to true before issuing a git command.

- name: add bar.txt to foo.git
  shell: export GIT_SSL_NO_VERIFY=true; git add bar.txt


Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





Please enter f8405 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |