puppet 4.4 之前的版本不支持http
方式同步文件
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,
此参数是文件不存在时才创建,应删去
调用示例
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' }
[root@itop puppet]# tree utils/ utils/ └── manifests ├── init.pp └── wget.pp
init.pp
class utils { include utils::wget }
wget.pp
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"] } } }
调用
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' }