
如何使用 puppet 自動安裝特定版本的 git?
apt-get update && apt-get install git-core
在我的 12.04 ubuntu 伺服器上,git 版本為 1.7.9。
我必須有 1.7.10 或更高版本。
我可以看到兩個選項。 1. 新增 ppa
2. 從來源安裝 git
我認為添加 ppa 比從原始碼編譯更容易,所以這就是我正在嘗試的。
我嘗試過使用puppetlabs/apt 模組安裝 git-core ppa,但 puppet 運行後我的 git 版本仍然是 1.7.9。
root@gitlab:~# puppet module list
/etc/puppet/modules
├── puppetlabs-apt (v1.2.0)
├── puppetlabs-git (v0.0.3)
├── puppetlabs-stdlib (v4.1.0)
└── ruby (???)
root@gitlab:~# cat /etc/puppet/manifests/git.pp
class { 'apt': }
apt::ppa { 'ppa:git-core/ppa':
before => Exec['apt-get update'],
}
exec{'apt-get update':
path => ['/usr/bin', '/usr/sbin'],
}
package {'git-core':
ensure => latest,
require => Exec['apt-get update'],
}
root@gitlab:~# puppet apply /etc/puppet/manifests/git.pp --verbose
Info: Loading facts in /etc/puppet/modules/stdlib/lib/facter/facter_dot_d.rb
Info: Loading facts in /etc/puppet/modules/stdlib/lib/facter/pe_version.rb
Info: Loading facts in /etc/puppet/modules/stdlib/lib/facter/puppet_vardir.rb
Info: Loading facts in /etc/puppet/modules/stdlib/lib/facter/root_home.rb
Warning: Config file /etc/puppet/hiera.yaml not found, using Hiera defaults
Info: Loading facts in /etc/puppet/modules/stdlib/lib/facter/facter_dot_d.rb
Info: Loading facts in /etc/puppet/modules/stdlib/lib/facter/pe_version.rb
Info: Loading facts in /etc/puppet/modules/stdlib/lib/facter/puppet_vardir.rb
Info: Loading facts in /etc/puppet/modules/stdlib/lib/facter/root_home.rb
Info: Applying configuration version '1379214336'
Notice: /Stage[main]//Exec[apt-get update]/returns: executed successfully
Notice: Finished catalog run in 5.80 seconds
root@gitlab:~# git --version
git version 1.7.9.5
答案1
git-core
不是該 PPA 中的軟體包 - 您想要git
代替(並且可能git-core
從 Ubuntu 儲存庫中刪除)。
答案2
正如 Shane 所提到的,您應該在套件定義中使用git
而不是使用。git-core
此外,也無需建立Exec['apt-get update']
依賴項,因為模組已經處理了該問題。
模組中的程式碼:
exec { "add-apt-repository-${name}":
...
notify => Exec['apt_update'],
...
}
因此,如果你想讓 git 始終保持最新,你應該這樣做:
class {'ntp': always_apt_update => true, }
和
package {'git':
ensure => latest,
require => Apt::Ppa['ppa:git-core/ppa'],
}