我有以下Ansible playbook文件,它試圖在一組CentOS 6盒子上管理printers.conf。如何使用Ansible乾淨地管理printers.conf?
---
# file: roles/common/tasks/config-cups.yml
# Configure printing
- name: ensure cups is installed
yum: pkg=cups state=installed
# We want to compare the local and remote printers.conf files so that
# we can predetermine if the copy needs to happen. According to a
# comment in the default printers.conf file, we can't write
# printers.conf while cups is running. But to be idempotent, we want
# to avoid stopping the cups service if we don't need to.
- stat: path=printers.conf
register: locst
- stat: path=/etc/cups/printers.conf
register: remst
# can't write printers.conf while running, so says the default file
- name: ensure cups is stopped
service: name=cups state=stopped
when: locst.stat.md5 ne remst.stat.md5
- name: Configure printers
tags: configuration
copy: >
src=printers.conf
dest=/etc/cups/printers.conf
mode=600 owner=root group=lp
notify:
- restart cups
- name: Enable the cups service
service: name=cups enabled=yes
- name: Ensure cups is running
service: name=cups state=started
不幸的是,我收到錯誤從when
條件控制所述杯服務的停止「致命:locst.stat.md5 NE remst.stat.md5:[hostxxx] =>錯誤而評價條件」。
有沒有辦法看到被評估的條件中的值?在這裏添加-vvv
並沒有幫助我。
還是有另一種方式來調試條件?
EDIT1:
顯然,統計模塊始終遠程 - 它不能用於匹配在角色本地printers.conf /普通/文件/ printers.conf
TASK: [common | stat path=printers.conf] **************************************
<hostxxx> ESTABLISH CONNECTION FOR USER[...]
<hostxxx> REMOTE_MODULE stat path=printers.conf
[...]
ok: [hostxxx] => {"changed": false, "stat": {"exists": false}}
這將是我的「評估條件時出錯」的來源。
所以我仍然不知道如何幹淨地管理文件。我不想將md5值編碼到任務中。
這個stackoverflow question正在尋找幾乎相同的東西。
EDIT2:
雖然我現在能夠得到的統計模塊對本地文件執行,使用local_action
和較長的路徑變通的lack of role-path searching in local actions,我仍然得到同樣的錯誤,而評估有條件的,儘管有有效的.stat.md5值。
- local_action: stat path=roles/common/files/printers.conf
register: locst
但是,我注意到md5值意外地不同。看來在運行時,cups會重新編寫printers.conf文件,其中包括所有內容,稱爲「StateTime」的時間戳。非常簡單,通過編寫配置文件來管理杯子。 AFAICT,乾淨地管理杯子的唯一方法,使得它只會每次取下服務,都是在比較之前過濾現有的printer.conf,或者不太合理,編寫webscraper來操作接口杯希望您用來配置打印機。
我在-vvv輸出中找到了錯誤的源頭:「stat path = printers.conf」與本地文件不匹配。 – 2014-10-02 19:29:35