Ansible register on template is not working

ansible

I'm trying to restart nginx in my ansible playbook if I changed the configuration. The configuration copy is done via template.

- name: update nginx.conf
  template: src=../templates/nginx_global_conf.conf.j2 dest=/etc/nginx/nginx.conf
  sudo: yes
  register: nginx_conf
- name: restart nginx if needed
  shell: service nginx restart
  when: nginx_conf.changed

Even if I'm getting:

TASK: [webapp | update nginx.conf] ********************************************
changed: [IPADDRESS]

I ALWAYS get:

TASK: [webapp | restart nginx if needed] **************************************
skipping: [IPADDRESS]

Tried also instead of shell:

action: service name=nginx state=restarted enabled=yes

It is not the problem. The register that isn't signalling is…

Best Answer

OK. Apparently I had the same nginx_conf in a different yml I included. Keeping the question here because there are quite some good tips. Thanks to all the helpers