7

I would like to have one central git repository for all my servers' etckeeper .git repos. Here the suggestion was to use a file in /etc/etckeeper/commit.d, which basically looks like this, assuming that a git repo had been set up in somedir on somehost:

#!/bin/sh
cd /etc
git push faruser@farhost:somedir

The problem with this is, that it would be really nice to have all servers in the same repo on the central server. I tried

git push faruser@farhost:somedir/server1

but that failed.

As you can see, I've never worked with git before ... Any ideas on how this can be accomplished is greatly appreciated :)

Cheers,

Andreas

5 Answers 5

2

I can understand wanting a central place with all your config info, but you probably want them to still be their own separate repositories, just in a central location. To do so, lookup how to push to remote locations in git (using git push). Then you'll need to set up access to that location from all your servers, at which point you can push from all of them. At which point the suggestion you pointed to should work.

1
  • 1
    I've been looking at having a template config in the master and then creating a branch for each server so I can do server-specific stuff like networking-scripts etc. Does this approach make sense? Sep 26, 2013 at 13:08
3

In addition to the good answer from pjz, here is how it could be done, step by step:

Create the file /etc/etckeeper/commit.d/60-push (dont forget to chmod+x it) on the clients.

    #!/bin/sh
    git push central_server:/var/git/client_name.git master

central_server is defined in the ssh config, see below. /var/git/client_name.git is the directory on the central server, containing the git repo.

The ~/.ssh/config from root(!) should contain something like this:

    host central_server
    Hostname 192.168.0.1
    User etckeeper #a user on the central server 
    IdentityFile ~/.ssh/custom_key # key is in authorized_keys in
                 #etcpeeper@central_server:~/.ssh/authorized_keys

Then you need to init the git repo on the central_server

    mkdir /var/git/client_name.git
    su etckeeper
    cd /var/git/client_name.git
    git --bare init

Test it with a minor edit in /etc and then a etckeeper commit "test push'ing".

2

You have to set up the remote host is such an way, that the local user (i asume root, as you use etckeeper) is allowed to push to the remote repository. How to do this is depending on the way you want your git-repos on the remote-site to be published/available. For example when using git via ssh you would most likely setup an sshkey-pair without passphrase and therefor allow the the local root to login at the reomteside without (keyoard-,...) ineraction. And yes, when pushing to the remote site, the repository has to be existing, so at least an empty repo has to be present. So first tell us the exact situation you working with and the exact error your getting.

1

I think that the initial question is how to push to different branches in the same repo. One way to archive this is to use the syntax:

git push faruser@farhost:somedir master:server1

This will push the local 'master' branch to the remote 'server1' branch. You can have variation on this, such as:

git push faruser@farhost:somedir master:auto/$(hostname)

Several remarks:

  1. as all branch do not have a common ancestor, you will perhaps need a --force for the first commit

  2. for the same reason, in the remote repo, you will see n linear independent history. In particular, you won't easily see the common part of your various branch. Idea for a project: take several git branch, create new ones to share common update and ensure that state in initial commits are also present in commits rewritten (i.e. rewrite the history by adding commit/merge/... but be sure to see the state of the initial commits)

0

At least on debian there is an option in etckeeper.conf.

...
# To push each commit to a remote, put the name of the remote here.    
# (eg, "origin" for git).
PUSH_REMOTE="origin"
...

After manually adding remote to git repos it should work out of the box

1
  • That would work for a single server's /etc in a remote repo – but doesn't explain how that remote repo could deal with multiple machines (as explained in the other answers, either via separate repos or via branches).
    – Izzy
    May 4, 2018 at 14:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .