Need to run some preparation tasks on your host in case of package update?
You can trick Ansible to run single task in check mode to predict the result
with check_mode: yes
parameter:
- name: "(CHECK MODE!) Need to update docker-engine?"
apt:
name: docker-engine
state: latest
check_mode: yes
register: apt_check
- name: "Remove ourselves from load balancer before update"
command: "/opt/bin/remove_host_from_balancer.sh {{ inventory_hostname }}"
delegate_to: balancer
when: apt_check | changed
- name: "Update docker-engine"
apt:
name: docker-engine
state: latest
register: apt_res
- name: "Enable ourselves on balancer"
command: "/opt/bin/add_host_to_balancer.sh {{ inventory_hostname }}"
delegate_to: balancer
when: apt_res | changed