command always says something changed, even when nothing actually changed?

I’m using command to run a2ensite, a2dissite, a2enmod, etc. Every time I run the playbook, those tasks come back as having changed something. Even when no site or module has been added or removed since the last time the playbook was run.

Is there a better way to run those tasks? Or should I just ignore the “changed” status?

Should I just make sure I know which symlinks to disable and use the file module to set their state to absent?

use creates/removes= and point to the symlink that would exist or not

Also in 1.3, there is a “when_changed” keyword you can use with register.

It’s in the docs if you want to read about it – Advanced playbooks page.

❦ Michael DeHaan <michael@ansibleworks.com>:

Also in 1.3, there is a "when_changed" keyword you can use with register.
It's in the docs if you want to read about it -- Advanced playbooks page.

Do you mean changed_when?
https://github.com/ansible/ansible/blob/devel/docsite/latest/rst/playbooks2.rst#overriding-changed-result

This does not work in case of a2ensite, a2enmod etc. They do not provide an
alternate exit code if a module/site is already enabled. They always return 0.

So in this case, creates= is the way to go.

Of course.

I’m just sharing the complete answer.

It’s been a while since I checked, but do Redhat style distros like CentOS use a2en* and a2dis* commands? I’ve run into a couple that used the *-enabled and *-available directories, but I’m not sure that’s the default behavior.

The reason I ask is that I was just pondering about writing a module that would do what I want, and it’d be nice if it worked for both both Redhat and Debian style distros. Something like:

apache2_vhost: name=vhostfilename state=enabled
apache2_mod: name=rewrite state=available

I don’t think I have enough Ansible knowledge to do that quite yet, but even just trying would be a good learning experience.

Hi David,

unfortunatelly these are debian-like distribution specific directories. Some control panels (know about ISPConfig) create and use them on RHEL like systems, but it is not native.

David

Do Redhat style distros have a default behavior I could rely on in an ansible module that works the way I described?

I manage the sites-enabled directories with templates directly, and don’t use the symlink method here.
Or you could just use the file module to manage the symlinks directly (which I do for the modules).

On Red Hat based distributions I just drop the vhosts files directly into conf.d and remove them when I don’t want them there.