Prevent fake "changed"

Hello,

I’m performing the following tasks :

  • name: Install ElasticSearch .deb file
    command: dpkg -Ei /home/ubuntu/elasticsearch-{{elasticsearch_version}}.deb
  • name: Updating ElasticSearch config

copy: src=elasticsearch.conf.yml dest=/etc/elasticsearch/elasticsearch.yml
notify: restart elasticsearch

  • name: Updating ElasticSearch defaults
    copy: src=elasticsearch.default.conf.yml dest=/etc/default/elasticsearch
    notify: restart elasticsearch

And obviously the second task is always run. So at the end of my playbook I have always at least 1 “changed”.

I don’t find it very satisfying… So I am looking for a way to prevent this.

I considered using a where clause where I would check the elastic search version (dpkg -s elasticsearch | grep ‘Version’) but I would somehow need a shell task and a register for that and it would still appear as “changed”.

I considered also using notify on the download but what about the other tasks that need the install ? They cannot be defined as handlers of the install because I want to be able to change the config (execute task 3 and 4) even if there is no new version of the package.

Am I right about this ? Is there another way ? Is it foolish to hope for 0 “changed” on consecutive runs ? Or is it really something I should chase ?

I hope I made myself clear !

Thanks a lot for your amazing work.

There’s an open pull request for an “ignore_changed: True” option on the task in Ansible 1.3

Though you may also wish to use the ‘creates=’ parameter to control the change state

Of course since you are invoking dpkg, I’d think you could also just use the apt module from a repository if it were available, which it might not be.

Thanks,
I can indeed use the creates parameter (in my case creates=/usr/share/elasticsearch/lib/elasticsearch-{{elasticsearch_version}}.jar).
I think it’s exactly what I needed !