in this particular case you might add a
- name: Install mysql server
apt: pkg=mysql-server state=installed
notify: remove default my.conf
and change the remove default to a handler.
it should only fire when installing the package.
however that seems to have a lot of assumptions.
run a shell script that checks if its a file and moves it away if so
I would likely modify your example do something like this:
- name: Install mysql server
apt: pkg=mysql-server state=installed
register: $installed_mss
- name: Remove mysql config file
file: path=/etc/mysql/my.cnf state=absent
when_changed: $installed_mss
- name: Symlink mysql conf
file: src=/srv/degen/misc/deploy/my.cnf
dest=/etc/mysql/my.cnf state=link
notify: Restart mysql
when_changed: $installed_mss
The reason we don't have file forcing between link and file states (or
file and link) for the most part is that could mean too many different
things about how to resolve that particular confusion, and I'd prefer
if things be explicit.
If done with changed variables (above), it still only runs when needed
and that should be fine.