English 中文(简体)
SaltStack - Git as a File Server
  • 时间:2024-12-22

SaltStack - Git as a File Server


Previous Page Next Page  

Git is an open-source distributed version control system. It can be used to keep a track of changes in any files. Salt sends files from Git repositories using the Git file server. You can configure Git to the fileserver_backend pst option and if you need to configure one or more repositories, you can do so by using the gitfs_remotes option.

This chapter explains about how to install and configure the Git file server. Before moving towards the installation, you must have the following prerequisites.

Salt Server Prerequisites for Using Git

The minimal requirement for the salt server to use Git as the file server is as follows −

    pygit2

    Dulwich

Pygit2 and Dulwich are configured using the gitfs_provider parameter in the master config file. If gitfs_provider is not configured in the master file then Salt will prefer pygit2, if the suitable version is available, followed by GitPython and Dulwich.

Install pygit2

The following commands are used to install pygit2 in the Fedora and Ubuntu based systems −

    Fedora-based system

yum install python-pygit2

    Ubuntu-based system

apt-get install python-pygit2

Here, the minimum supported version of pygit2 is 0.20.3.

Install GitPYTHON

GitPython can be easily installed on the master using the yum / apt command as shown below.

    Fedora-based system

yum install GitPython

    Ubuntu-based system

apt-get install python-git

Install DULWICH

Dulwich can be easily installed on the master using the yum command.

    Fedora-based system

yum install python-dulwich

    Ubuntu-based system

apt-get install python-dulwich

Now, we have installed all the dependencies for the Git file server. Let us now configure this Git file server using the fileserver_backend section in the master config file.

Backend Configuration

In order to use the Git file server, you need to add Git in the fileserver_backend pst in the master config file. It is described as follows −

fileserver_backend:
   - git

Let us further understand how to configure the Git file server in a remote configuration.

gitfs_remotes Configuration

You can specify any one or all of the URLs such as git://, https://, file://, or ssh:// for the gitfs_remotes configuration in the master file. This is used to search for the requested files.

The simple https URL specification is defined below.

gitfs_remotes:
   - https://github.com

The ssh configuration can be done as shown below.

gitfs_remotes:
   - git@github.com:user1/sample.git
   - ssh://user@domain.tld/path/to/sample.git

Now, we have configured the Git file server using the two options fileserver_backend and gitfs_remotes.

Restart Master

After making all the changes in the master file, now restart the master to load all the configurations in the Git file server.

Multiple Remotes Configuration

The following command is used for multiple configuration in gitfs_remotes in the master file.

gitfs_remotes:
   - git://github.com/sample/sample1.git
   - https://github.com/sample/sample2.git
   - file:///root/user/sample

Here, the repositories sample1.git, sample2.git, and sample.doc may have the following files.

sample1.git:
   top.sls
   
sample2.git
   edit/vimrc
   
sample.doc
   edit/vimrc
Advertisements