stopping daemons before apt-get remove?

42 views
Skip to first unread message

Kevin Burton

unread,
Dec 20, 2014, 6:38:39 PM12/20/14
to ansible...@googlegroups.com
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:
    - stop foo

... is this possible? I guess I could stat the init script first but that adds more complexity. 

Dan Vaida

unread,
Jan 5, 2015, 2:57:49 PM1/5/15
to ansible...@googlegroups.com
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 <packagename>', save that in a list, do a 'apt-get remove --purge <packagename>' 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 :)

Tom Bamford

unread,
Jan 6, 2015, 3:59:12 AM1/6/15
to ansible...@googlegroups.com

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

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/37211c6a-2e21-4a92-9e9a-59d6b8afd4b9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages