2016-07-19 80 views
2

我試圖自動化在Ansible Debian上的exim4配置 - 我們一直在手動配置,直到這一點 - 但我卡在階段我通常在那裏運行dpkg-reconfigure exim4-config自動化*只是* exim4配置與debconf設置選擇與Ansible

我可以自動執行這些步驟很輕鬆地:

  • 更新在/etc/exim4/exim4-config.conf.conf
  • 運行dpkg-reconfigure --frontend noninteractive exim4-config

他們在劇本運行良好conf文件,但是問題是,不是所有的我在交互式提示中看到的選項位於此conf文件中。例如,第二個設置System mail name未在conf文件的任何位置指定。也不是最後一個設置,Root and postmaster mail recipient,這也將停止顯示了在交互提示第一次配置後(這是爲什麼?)

然後我看到有些人已經開始使用debconf-set-selectionshere)建議,我試圖尋找到 - 我安裝了debconf-utils包,然後運行debconf-get-selections - 然後我看到了所有的選項,但現在我想知道是否有一種方法可以使用debconf-set-selections而不必使用設置所有設置的文件全部曾經,因爲我只是想改變與exim4相關的值。我試圖避免覆蓋可能會設置的任何其他值(不與exim4關聯),如果我需要再次運行劇本。

短的debconf-get-selections輸出寫入文件,然後使用Ansible的lineinfile/template模塊來代替我想改變的價值觀,是有可能的會對此更簡單的方法?我寧願避免這種方法。

回答

2

這有點晚,但我建議你使用ansible debconf module(它基本上是一個debconf-set-selections)。

像這個例子:

- name: Debconf question dc_eximconfig_configtype 
    debconf: name='exim4-config' 
    question: 'exim4/dc_eximconfig_configtype' 
    value: 'internet site; mail is sent and received directly using SMTP' 
    vtype: select 

或者這一個:

- name: Debconf question mailname 
    debconf: name='exim4-config' 
    question: 'exim4/mailname' 
    value: '{{ inventory_hostname }}' 
    vtype: string 

但是,如果你是重新配置進出口(你一旦配置後話),那麼你必須刪除2個文件在執行dpkg-reconfigure之前,可以使用以下命令完成:

- name: remove exim config files 
    file: path={{ item }} state=absent 
    with_items: 
    - "/etc/exim4/update-exim4.conf.conf" 
    - "/etc/mailname" 

最後,做一個dpkg-reconfigure,它也重新啓動exim。

- name: Reconfigure package exim4-config 
    command: dpkg-reconfigure -fnoninteractive exim4-config