I need the opposite of notify.
Basically, I have a ‘foo-off’ role to turn services / daemons off for a specific host.
So if foo is the service, I want to stop foo , then apt-get remove it.
- service: name=foo state=stopped
… because the second time it’s run the daemon isn’t present because the package is removed.
So what I need is kind of a notify that runs BEFORE a task.
So something like
- name: apt-get remove foo
apt: name=foo state=absent
before:
… is this possible? I guess I could stat the init script first but that adds more complexity.
I’d construct a list var with the packages names and pass it to two tasks: first one would stop and disable the services and the second one would remove the packages.
Some packages are stopping the daemons as part of the uninstall/purge, some don’t.
You could also do a ‘dpkg-query -L ’, save that in a list, do a ‘apt-get remove --purge ’ and then call the file module with state=absent and ignore_errors: True to ingest the previous list.
Not what you were expecting but it’s simpler than stat’ing the init file
You could first check if the package is installed and register a variable to that effect.
- shell: dpkg -l foo
changed_when: False
failed_when: False
register: foo_installed
- service: name=foo enabled=no state=stopped
when: foo_installed.rc == 0