2016-11-08 53 views
1

我是新來的木偶和計劃在我們的環境中實施它。在木偶中使用因素事實

我有在不同版本的Redhat上運行的puppet代理。

現在,我打算推動來自木偶大師的回購文件,我需要你的指導來實現它。

我有以下清單。

file { 'local_repo': 
    ensure => file, 
    path => '/etc/yum.repos.d/local.repo', 
    mode => "600", 
    source => 'puppet:///modules/repo/rhel7.1', 
} 

file { 'local_repo': 
    ensure => file, 
    path => '/etc/yum.repos.d/local.repo', 
    mode => "600", 
    source => 'puppet:///modules/repo/rhel6.7', 
} 

當我執行Facter CLI時,我得到下面的輸出。

[[email protected] ~]# facter os 
{ 
    architecture => "x86_64", 
    family => "RedHat", 
    hardware => "x86_64", 
    name => "RedHat", 
    release => { 
    full => "7.2", 
    major => "7", 
    minor => "2" 
    } 
} 

我想利用上面的輸出並相應地執行我的清單。也就是說,如果puppet代理在Redhat 7.1上執行,那麼Puppet master使用相應的文件。

回答

3

您可以通過使用source屬性中的Facter變量,然後在字符串中插入它來完成此操作。請注意,您的'必須更改爲"以插入字符串中的變量。

Facter 2 /木偶3:

file { 'local_repo': 
    ensure => file, 
    path => '/etc/yum.repos.d/local.repo', 
    mode => "600", 
    source => "puppet:///modules/repo/rhel${::os['release']['full']}", 
} 

Facter 3 /木偶4:

file { 'local_repo': 
    ensure => file, 
    path => '/etc/yum.repos.d/local.repo', 
    mode => "600", 
    source => "puppet:///modules/repo/rhel${facts['os']['release']['full']}", 
} 

你可以找到有用的文檔在這裏:https://docs.puppet.com/puppet/4.8/reference/lang_facts_and_builtin_vars.html

這是最新的版本,但也包含傳統的Puppet/Facter信息。

+0

非常感謝馬特,小錯誤是您錯過了添加版本。 source =>「puppet:/// modules/repo/rhel $ {facts ['os'] ['release'] ['full']}」, – sagar

+0

@sagar真的,我誤解了上面的事實散列。爲此編輯答案。如果這個答案對你有幫助,那麼請接受它。 –

+0

我沒有找到答案。請標記爲已解決 – sagar