Bootstrap FreeKB - Ansible - Create a compressed archive of a Git repository
Ansible - Create a compressed archive of a Git repository

Updated:   |  Ansible articles

The most basic way to use Git is to use the git clone command to clone an origin Git repository (such as example.git) to a directory on your PC (such as /home/john.doe/git), make a change to a file in the cloned repository on your PC (such as example.txt), use the git commit command to commit the change to the file, and to then use the git push command to upload the file to the origin Git repository.

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

The git module can be used to create 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

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


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