2017-09-03 159 views
0

我試圖在CentOS7中啓用carbon-aggregator以啓用systemctl服務,帶有可變變量「ansible_processor_cores」。它不起作用。 這裏是角色例如:Ansible在CentOS7中啓用{0 .. {{ansible_processor_cores}}}的systemctl服務不起作用

- name: enable carbon-aggregator 
    service: 
    name: '[email protected]{0..{{ansible_processor_cores -3}}}' 
    enabled: yes 
    state: started 
    daemon_reload: yes 

Carbon.conf.j2:

{% for aggr in range(ansible_processor_cores -2) %} 
[aggregator:{{aggr}}] 
{% endfor %} 

錯誤是:

失敗! => {「changed」:false,「failed」:true,「msg」:「無法啓動 service carbon-aggregator @ {0..1}:作業爲 carbon-aggregator @ \ x7b0..1 \ x7d .service失敗,因爲控制 進程退出時顯示錯誤代碼。請參閱\「systemctl狀態\」 \「carbon-aggregator \\ x7b0..1 \\ x7d.service \」\「和\」journalctl -xe \「細節\ n「}

正如我在這裏看到的是試圖使一些服務,我沒有問:

碳匯聚@ \ x7b0..1 \ x7d.service

我不知道他們來自哪裏。 如果我會做手工,它完美的作品那樣:

sudo systemctl enable [email protected]{0..1} 

有什麼建議?

+0

使用此模塊,您只指定了一項服務,這不會按照您認爲的方式來解釋。你必須使用with_items來循環。 – papey

+0

@papey你有沒有像它應該如何尋找這個具體例子的例子? – muzafarow

+0

我正在挖掘找到一個乾淨的方式來做到這一點 – papey

回答

2

要啓動多項服務,您可以使用with_sequence循環。有關詳細信息,請參閱Loops文檔,但我相信with_sequence的文檔可能不正確。

一個例子可能看起來像:

- name: enable carbon-aggregator 
    service: 
    name: '[email protected]{{ item }}' 
    enabled: yes 
    state: started 
    daemon_reload: yes 
    with_sequence: start=0 end={{ansible_processor_cores-1}} 

在一個系統四個核,上述循環會調用service模塊四次,name:設置爲[email protected][email protected][email protected],並[email protected]