用户工具

站点工具


02-工程实践:配置管理:puppet:remote_file

远程文件

puppet 4.4 之前的版本不支持http方式同步文件

snippet.puppet
  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, 此参数是文件不存在时才创建,应删去

调用示例

snippet.puppet
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'
}

做成模块

snippet.bash
[root@itop puppet]# tree utils/
utils/
└── manifests
    ├── init.pp
    └── wget.pp

init.pp

snippet.puppet
class utils {
	include utils::wget
}

wget.pp

snippet.puppet
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"]
    }
  }
}

调用

snippet.puppet
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'
  }

参考

02-工程实践/配置管理/puppet/remote_file.txt · 最后更改: 2020/04/09 00:42 由 54.36.150.129