2016-05-15 39 views
0

我有一個包含這個短語(我的問題是關於在年底生產塊)的傀儡清單,用於設置MySQL配置文件:添加具有puppetlabs mysql的模塊定製服務器選項

class web_mysql_server { 

    include web_mysql::packages 
    include web_mysql::mysql_server 
} 

class web_mysql::packages { 

    Package { ensure => installed } 
    package { 'libmysqlclient-dev': } 
} 

class web_mysql::mysql_server { 

# Qualified keys (dot notation: web_mysql_server.mysql_database) isn't available 
    # until hiera 2.0. 
    $mysql_config = hiera('web_mysql_server') 

    # https://forge.puppetlabs.com/puppetlabs/mysql 
    class { '::mysql::server': 
root_password => '...', 
remove_default_accounts => true, 
override_options  => { 
    # The data in this block gets written to /etc/mysql/my.cnf. 
    'mysqld'  => { 
    max_connections => '1024', # No good reason but parroting others. 
    key_buffer_size => '512M', # No good reason but parroting others. 
    }, 

    'production' => { 
    adaptor => 'mysql2', 
    database => $mysql_config['mysql_database'], 
    user  => $mysql_config['mysql_username'], 
    password => $mysql_config['mysql_password'], 
    host  => '0.0.0.0', 
    encoding => 'UTF8', 
    }, 

但有時我可能會喜歡數據庫作爲臨時數據庫,所以稱它爲生產有點混亂。沒問題,我最近了解到hiera,這是我的錘子對所有釘子今天:

$mysql_config['mysql_name'] => { 
    adaptor => 'mysql2', 
    database => $mysql_config['mysql_database'], 
    user  => $mysql_config['mysql_username'], 
    password => $mysql_config['mysql_password'], 
    host  => '0.0.0.0', 
    encoding => 'UTF8', 
    }, 

不,那是不行的,雖然錯誤("syntax error at line (...with '=>'...), expected '}'")是不是非常發人深省。

(「Key」可能是錯誤的詞,請糾正我,我對puppet有點新,而這本身也可能是我爲什麼不能通過Google搜索和閱讀來回答這個問題。)

感謝您的指點。

+0

看來你傳遞'production'作爲參數傳遞給一個類或資源, 對?你能發佈更大的背景,包括類/資源嗎? – Mifeet

+0

@Mifeet當然,完成了。 – jma

+0

你的代碼有問題。在一個類定義中,比如'web_mysql :: mysql_server',你可以包含/聲明資源,其他類,賦值給變量等。''production'=> {...}'代碼段既不是。你期望這段代碼能做什麼? – Mifeet

回答

1

更新:我現在的mysql模塊提供了一個選項,添加部分配置文件開箱見。下面是如何應根據所使用的documentation

$override_options = { 
    $mysql_config['mysql_name'] => { 
    adaptor => 'mysql2', 
    database => $mysql_config['mysql_database'] 
    # ... 
    } 
} 

class { '::mysql::server': 
    root_password   => 'strongpassword', 
    remove_default_accounts => true, 
    override_options  => $override_options, 
} 

或者,如果你把mysql_name值根據不同的hiera鍵可以節省一些代碼:

$override_options = { 
    hiera('mysql_name') => hiera('web_mysql_server') 
} 

原來的答覆

如果您的實際意圖只是創建一個配置文件,最好的方法是使用templateserb syntax

下面是一個例子。首先,您將my.cnf.erb文件放入模塊的templates目錄(例如,modules/web_mysql/templates):

[<%= @mysql_config['mysql_name'] %>] 
adaptor = mysql2 
database = <%= @mysql_config['mysql_database'] %> 
user  = <%= @mysql_config['mysql_username'] %> 
password = <%= @mysql_config['mysql_password'] %> 
host  = 0.0.0.0 
encoding = UTF8 

你可以使用這個模板在你web_mysql::mysql_server類來創建配置文件:

class web_mysql::mysql_server { 
    # ... 
    $mysql_config = hiera('web_mysql_server') 
    file { '/etc/mysql/my.cnf': 
    ensure => 'present', 
    content => template('web_mysql/my.cnf.erb'), 
    } 
} 

0

您使用的方式web_mysql::mysql_server表示該班有參數,稱爲production。如果是這種情況,則在使用課程時必須使用該名稱。相反,爲什麼不只是調用參數mysqlclient,因爲它似乎是客戶端配置參數?


回答到原來的問題:

無論版本的清單是有效的木偶。例如,把這個在我的清單:

'production' => { 
    adaptor => 'mysql2', 
} 

和運行puppet apply --noop --modulepath modules manifests/host.pp結果:

Error: Could not parse for environment production: Syntax error at '=>' at [...]/host.pp:1:14 on node hostname 

你的意思是說這樣的事情?

$database_configuration = { 
    adaptor => 'mysql2', 
    database => $mysql_config['mysql_database'], 
    user  => $mysql_config['mysql_username'], 
    password => $mysql_config['mysql_password'], 
    host  => '0.0.0.0', 
    encoding => 'UTF8', 
} 
+0

謝謝。我認爲@Mifeet是正確的,要求我添加周圍的代碼,現在它更有意義嗎? – jma

相關問題