这是我的清单,也请原谅我的格式。最底部是错误。我该如何重构它以使其正常工作?我知道它告诉我 /etc/yum.repos.d 被多次使用,但我需要多次使用它才能完成我需要做的事情,即删除 /etc/yum.repos.d 目录并将其与本地存储库中的模板一起添加回来。任何帮助都将不胜感激。
class profile::base {
#the base profile should include component modules that will be on all nodes
#Remove Directory
#file {'Remove_Directory':
# ensure => absent,
# path => '/etc/yum.repos.d',
# recurse => true,
# purge => true,
# force => true,
# }
#Add Directory
file {'Add_Directory':
ensure => directory,
path => '/etc/yum.repos.d',
recurse => true,
purge => true,
force => true,
}
#Copy Repo Template in directory
file { 'Copy_Template':
path => '/etc/yum.repos.d',
ensure => file,
content => template('profile/local-repos.repo.epp'),
}
}
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Resource Statement, Cannot alias File[Copy_Template] to ["/etc/yum.repos.d"] at (file: /etc/puppetlabs/code/environments/bastion/site/profile/manifests/base.pp, line: 24); resource ["File", "/etc/yum.repos.d"] already declared (file: /etc/puppetlabs/code/environments/bastion/site/profile/manifests/base.pp, line: 15) (file: /etc/puppetlabs/code/environments/bastion/site/profile/manifests/base.pp, line: 24, column: 1) on node sshtest.mmps.mcrc.cspm.marines.usmc.mil
答案1
我猜你想做的是类似以下的事情:
确保目录存在,但仅包含托管文件:
file { '/etc/yum.repos.d':
ensure => 'directory',
purge => true,
recurse => true,
force => true,
[...]
}
将托管文件添加到该目录:
file { '/etc/yum.repos.d/your-repo-file.repo':
ensure => 'present',
content => template('your-template'),
[...]
}
答案2
您可以使用本机 yumrepo 资源实现您想要做的事情。
首先,清除所有未管理的 yum 存储库。(我相信这就是您尝试使用 Add_Directory 文件资源执行的操作。)
resources { 'yumrepo':
purge => true,
}
然后,您可以定义您的本地存储库。
yumrepo { 'myrepo1':
...
}
yumrepo { 'myrepo2':
...
}