puppet 4.4 之前的版本不支持 http
方式同步文件。可以用如下代码来自定义远程文件功能:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
define remote_file($remote_location=undef, $mode='0644', $service=undef, $md5=undef){ exec{ "retrieve_${title}": unless => "/usr/bin/md5sum ${title} |/usr/bin/grep -w ${md5}", command => "/usr/bin/curl -s ${remote_location} --create-dirs -o /tmp${title} && /usr/bin/md5sum /tmp${title} |/usr/bin/grep -w ${md5} && /usr/bin/mv -f ${title} /tmp && /usr/bin/mv -f /tmp${title} ${title} || exit 1", #creates => $title, } file{$title: mode => $mode, require => Exec["retrieve_${title}"], notify => Service["$service"] } } |
creates => $title,
此参数是文件不存在时才创建,应删去
调用示例
1 2 3 4 5 6 7 |
remote_file { '/usr/local/bin/kube-proxy': mode => '0755', service => 'kube-proxy', md5 => '7f88a9057292971b10ad6de794f9ba62', remote_location => 'http://yum.intra.xxx.cn/soft/k8s/kube-proxy' } |
做成模块
也可以做成模块,结构如下:
1 2 3 4 5 |
[root@itop puppet]# tree utils/ utils/ └── manifests ├── init.pp └── wget.pp |
init.pp
1 2 3 |
class utils { include utils::wget } |
wget.pp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
class utils::wget { define remote_file($remote_location=undef, $mode='0644', $service=undef, $md5=undef){ exec{ "retrieve_${title}": unless => "/usr/bin/md5sum ${title} |/usr/bin/grep -w ${md5}", command => "/usr/bin/curl -s ${remote_location} --create-dirs -o /tmp${title} && /usr/bin/md5sum /tmp${title} |/usr/bin/grep -w ${md5} && /usr/bin/mv -f ${title} /tmp && /usr/bin/mv -f /tmp${title} ${title} || exit 1", #creates => $title, } file{$title: mode => $mode, require => Exec["retrieve_${title}"], notify => Service["$service"] } } } |
调用
1 2 3 4 5 6 7 8 9 |
class k8sdev::worker { include utils::wget utils::wget::remote_file { '/usr/local/bin/kube-proxy': mode => '0755', service => 'kube-proxy', md5 => '7f88a9057292971b10ad6de794f9ba62', remote_location => 'http://yum.intra.xxx.cn/soft/k8s/kube-proxy' } |
参考
1 2 |
1. https://serverfault.com/questions/639966/can-puppet-file-source-be-from-a-web-service 2. https://stackoverflow.com/questions/18844199/how-to-fetch-a-remote-file-e-g-from-github-in-a-puppet-file-resou |
发表回复