2014-09-18 33 views
0

好吧,這是我的任務:Ansible通知處理doen't執行

--- 
- name: copy source list 
    copy: src=sources.list dest=/etc/apt/sources.list 
    notify: update apt 

# - name: Update apt 
# shell: apt-get update 

- name: Install postgres 
    shell: apt-get install -q -y postgresql-9.1 
    #apt: name=postgresql-9.1 state=present 

- others tasks... 

這裏是我的處理程序:

- name: update apt 
    action: apt-get update 

當我運行它不會通知。

... 

TASK: [postgresql | copy source list] ***************************************** 
changed: [host_slave2] 
changed: [host_slave1] 
changed: [host_pgpool] 
changed: [host_master] 

TASK: [postgresql | Install postgres] ***************************************** 
changed: [host_slave1] 
changed: [host_master] 
changed: [host_slave2] 
changed: [host_pgpool] 

... 

複製後,我應該看到通知,什麼是錯的?

+1

通知來執行,在你取消或讓它運行到結束的遊程的盡頭?我建議增加冗長。最後,[apt * modules](http://docs.ansible.com/list_of_packaging_modules.html)非常棒。 – tedder42 2014-09-18 23:45:50

回答

-1

http://wherenow.org/ansible-handlers/

其實這個問題是需要強制的

--- 
- name: copy source list 
    copy: src=sources.list dest=/etc/apt/sources.list 
    notify: update apt 

- meta: flush_handlers 


- name: Install postgres 
    shell: apt-get install -q -y postgresql-9.1 
    #apt: name=postgresql-9.1 state=present 

- others tasks... 

handler: 

- name: update apt 
    action: apt-get update 
1
--- 

- name: copy source list 
    copy: src=sources.list dest=/etc/apt/sources.list 
#http://docs.ansible.com/apt_repository_module.html 
    register: update_apt 

- name: Update apt 
    apt: update_cache=yes cache_valid_time=86400 
#http://docs.ansible.com/apt_module.html 
    when: update_apt is defined and update_apt.changed == True 

- name: Install postgres 
    shell: apt-get install -q -y postgresql-9.1 
    #apt: name=postgresql-9.1 state=present 

- others tasks... 
+0

雖然建議的答案會起作用,但並不是按照原始問題使用有效的處理程序。 – 2017-02-16 08:30:02