好的,这是我的任务:
---
- 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]
...
复制后我应该看通知,有什么问题?
答案 0 :(得分: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...
答案 1 :(得分:0)
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