简体   繁体   中英

Cannot checkout git ssh repository with vcsrepo

So this is what I am using:

vcsrepo { "$base_dir":
    ensure => latest,
    provider => git,
    source => 'ssh://git@example.com:7999/EXAMPLE/example.git',
    require => File["$base_dir"],
    revision => $branch,
}

Which results in an error when I apply the puppet manifest:

Error: Could not create repository (non-repository at path)
Error: /Stage[main]/MyServer::Server/Vcsrepo[/usr/service/myserver]/ensure: change from absent to latest failed: Could not create repository (non-repository at path)

When I do:

git clone ssh://git@example.com:7999/EXAMPLE/example.git

It works.

Any ideas?

Likely you do not want to use force, since that would result in the git repo being deleted and cloned every time you applied your manifest, or just blowing away a directory with unrelated files that may not be replaceable! Instead, I suggest you take a look at the git provider's source code . There you can see exactly what is being done to determine if a repo exists or not. Specifically, the working_copy_exists? method.

In my case, the failure occurred because I had specified a ssh:// url as you have - but the existing repo had been cloned (via ssh) with a url like git@example.com:EXAMPLE/example.git . This meant when the working_copy_exists? method inspected the .git/config in the repo looking for an address with ssh:// , it was unable to find it! That causes vcsrepo to assume that the directory contents are unrelated and fail without a force.

The URL check is just one of several in that method, so if that is not the reason it is not correctly identifying your working copy, then it could be one of the other checks.

If the target directory exists as non-empty, add force option to clone repo.

vcsrepo { "$base_dir":
    ensure => latest,
    provider => git,
    source => 'ssh://git@example.com:7999/EXAMPLE/example.git',
    require => File["$base_dir"],
    revision => $branch,
    force => true,
}

Source: vcsrepo: git clone doesn't work if destination path already exists.

Based on this discussion https://groups.google.com/d/msg/puppet-users/ke5Nk1qwGGs/37dFA3tr5rIJ as well as personal experience,

vcsrepo wants to create the directory.

So if $base_dir is /tmp/foo/bar/baz, only thge /tmp/foo/bar directory should exist.

Also for the ssh to work correctly ( https://github.com/puppetlabs/puppetlabs-vcsrepo/blob/master/README.GIT.markdown#for-sources-that-use-ssh-eg-usernameserver ) , you have to add a user attribute to vcsrepo so that it picks up the correct ssh keys (annoying since it also assumes you want that user to own the newly cloned repo).

i think the parameter "safe_directory => true" is your friend.

I do in hiera and after doing that, if directory exist, puppet do a git pull.

Error without put "safe_directory: true". ( i do in hiera )

zabbix::agent::scripts:
 '/etc/zabbix.includes':
   ensure: 'latest'
   provider: 'git'
   source: 'https://git.x.com/es-public/linux-scripts-test.git'
   group: 'zabbix'
   owner: 'zabbix'

I got the error:

Notice: Vcsrepo[/etc/zabbix.includes](provider=git): Removing '/etc/zabbix.includes' from safe directory list
Notice: /Stage[main]/Profiles::Linux::Zabbix_agent/Vcsrepo[/etc/zabbix.includes]/ensure: Creating repository from latest
Error: Path /etc/zabbix.includes exists and is not the desired repository.
Error: /Stage[main]/Profiles::Linux::Zabbix_agent/Vcsrepo[/etc/zabbix.includes]/ensure: change from 'present' to 'latest' failed: Path /etc/zabbix.includes exists and is not the desired repository. (corrective)

Then i put the parameter "safe_directory: true"

zabbix::agent::scripts:
 '/etc/zabbix.includes':
   ensure: 'latest'
   safe_directory: true
   provider: 'git'
   source: 'https://git.x.com/es-public/linux-scripts-test.git'
   group: 'zabbix'
   owner: 'zabbix'

and all is OK with the new changes of git repository

Notice: Vcsrepo[/etc/zabbix.includes](provider=git): Adding '/etc/zabbix.includes' to safe directory list
Notice: /Stage[main]/Profiles::Linux::Zabbix_agent/Vcsrepo[/etc/zabbix.includes]/ensure: Updating to latest 'master' revision
Notice: /Stage[main]/Profiles::Linux::Zabbix_agent/Vcsrepo[/etc/zabbix.includes]/ensure: created (corrective)

Because the module add in /root/.gitconfig the next directive:

root@xxxx:/home/xxxx# cat ~/.gitconfig 
[safe]
    directory = /etc/zabbix.includes

If i do again the execution, the module doesn't execute anything, because i don't have any change in my git repository.

hope this help

You don't need the entire ssh:// path for the checkout. This module will handle that for you.

This was plucked from their examples :

vcsrepo { "/path/to/repo":
    ensure => present,
    provider => git,
    source => "git://example.com/repo.git"
}

Yours would look like:

vcsrepo { "$base_dir":
    ensure => latest,
    provider => git,
    source => 'git://example.com:7999/EXAMPLE/example.git',
    require => File["$base_dir"],
    revision => $branch,
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM