# suppressing autostart with debian packages

**URL:** <https://forum.ansible.com/t/suppressing-autostart-with-debian-packages/13293>\
**Category:** Ansible Project\
**Created:** [August 13, 2013, 7:02pm UTC](https://forum.ansible.com/t/suppressing-autostart-with-debian-packages/13293 "2013-08-13T19:02:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abhijit\_Menon-Sen2](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@Abhijit\_Menon-Sen2](https://forum.ansible.com/u/Abhijit_Menon-Sen2)\
**Post date:** [August 13, 2013, 7:02pm UTC](https://forum.ansible.com/t/suppressing-autostart-with-debian-packages/13293/1 "2013-08-13T19:02:08Z")

</div>

Hi.

My playbook uses an apt: action to install a bunch of Debian packages.  
Some of these packages start the daemon automatically with the default  
configuration. For my purposes, I want to avoid this.

One way to do this reliably is to install a /usr/sbin/policy-rc.d file  
that does "exit 101". So I can do something like this:

&nbsp;&nbsp;&nbsp;&nbsp;- name: Install policy-rc.d  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;copy: src=policy-rc.d dest=/usr/sbin/policy-rc.d mode=0755

&nbsp;&nbsp;&nbsp;&nbsp;- name: Install packages  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;apt: pkg=$item state=installed  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_items: [git, vim, …]

&nbsp;&nbsp;&nbsp;&nbsp;- name: Remove policy-rc.d  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file: path=/usr/sbin/policy-rc.d state=absent

Now, this works, but it's a very big hammer indeed. It would be nice if  
I could avoid installing and removing policy-rc.d unless it's required,  
i.e. unless I'm actually going to install some package. It's easy to do  
the removal conditionally: just turn it into a handler and notify it.

But I couldn't find any easy way to make the policy-rc.d installation  
conditional. Hence my "apt\_wouldinstall" proposal below:

&nbsp;&nbsp;&nbsp;&nbsp;[https://github.com/ansible/ansible/pull/3820](https://github.com/ansible/ansible/pull/3820)

With my proposed module, one could do something like this:

&nbsp;&nbsp;&nbsp;&nbsp;- name: Do we need to install anything?  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;apt\_wouldinstall: pkg=$item  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_items: packages\_needed  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: pkglist

&nbsp;&nbsp;&nbsp;&nbsp;- name: Install policy-rc.d if needed  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;copy: …  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: pkglist.changed

&nbsp;&nbsp;&nbsp;&nbsp;- apt: …  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;notify:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- remove policy-rc.d

Note that it's vastly easier to check if a given list of packages is  
installed using python-apt's cache[pkgname].is\_installed in a loop,  
compared to any shell-based way I've found to do it.

(There was a suggestion to use --check, but I think this was because I  
didn't explain my use case sufficiently well—I want to make the decision  
in the code, not interactively.)

I welcome any comments about this situation, including alternative  
solutions for the problem (maybe a way to trigger handlers before  
an action would be nicer?, or suggestions to improve the code.

Thank you.

-- ams

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [August 14, 2013, 12:33am UTC](https://forum.ansible.com/t/suppressing-autostart-with-debian-packages/13293/2 "2013-08-14T00:33:12Z")

</div>

Yeah so I remember the pull request but didn’t get your context for it.

So for most users there’s no need of a “wouldinstall” module because you can run Ansible in check mode.

However, there’s no way to run just _one_ task in check mode, so it seems this is a feature request for check at task level.

apt: …  
check\_mode: True

It is much better to implement the above rather than implement a “would” type for every module.

---

<div class="post-metadata">

**Author:** ![Abhijit\_Menon-Sen2](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@Abhijit\_Menon-Sen2](https://forum.ansible.com/u/Abhijit_Menon-Sen2)\
**Post date:** [August 14, 2013, 2:48am UTC](https://forum.ansible.com/t/suppressing-autostart-with-debian-packages/13293/3 "2013-08-14T02:48:08Z")

</div>

Yes, that sounds much better. Thanks for the suggestion. I'll implement  
this and send an new pull request.

-- ams

---

<div class="post-metadata">

**Author:** ![Abhijit\_Menon-Sen2](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@Abhijit\_Menon-Sen2](https://forum.ansible.com/u/Abhijit_Menon-Sen2)\
**Post date:** [May 17, 2014, 5:25pm UTC](https://forum.ansible.com/t/suppressing-autostart-with-debian-packages/13293/4 "2014-05-17T17:25:54Z")

</div>

Hi.

I'm sorry it's taken so long, but here's a pull request that allows  
individual tasks to be run in check mode:

&nbsp;&nbsp;&nbsp;&nbsp;[https://github.com/ansible/ansible/pull/7439](https://github.com/ansible/ansible/pull/7439)

The patch was written by my colleague Carlos Chapi (Cc:ed) and tested by  
me (the original motivation for this feature was to find out if the apt  
module would install certain packages, so as to take some extra actions  
before and afterwards only if something's going to be installed).

For example (since the original context was so long ago):

&nbsp;&nbsp;&nbsp;&nbsp;- name: Check if Postgres needs to be installed  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;apt: name=postgresql-9.3 state=installed  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;check\_mode: True  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: wouldinstall

&nbsp;&nbsp;&nbsp;&nbsp;- name: Suppress autostart with policy-rc.d  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;copy:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;content="#!/bin/bash\nexit 101\n"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest=/usr/sbin/policy-rc.d mode=0755  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: wouldinstall.changed

&nbsp;&nbsp;&nbsp;&nbsp;- name: Install Postgres  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;apt: name=postgresql-9.3 state=installed  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: wouldinstall.changed  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: install

&nbsp;&nbsp;&nbsp;&nbsp;- name: Remove policy-rc.d  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file: path=/usr/sbin/policy-rc.d state=absent  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: install.changed

(My original proposal involved an "apt-wouldinstall" module, but Michael  
suggested the much more sensible per-task check\_mode setting.)

I can imagine many other "do x if y would happen" use-cases for this.

Thanks.

-- ams

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [May 19, 2014, 2:57am UTC](https://forum.ansible.com/t/suppressing-autostart-with-debian-packages/13293/5 "2014-05-19T02:57:31Z")

</div>

I’m not finding too many use cases for this.

Maybe help me understand, but I’m wanting to reduce language clutter here and this does not seem like it would be widely utilized.

---

<div class="post-metadata">

**Author:** ![Abhijit\_Menon-Sen2](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@Abhijit\_Menon-Sen2](https://forum.ansible.com/u/Abhijit_Menon-Sen2)\
**Post date:** [May 19, 2014, 4:23am UTC](https://forum.ansible.com/t/suppressing-autostart-with-debian-packages/13293/6 "2014-05-19T04:23:28Z")

</div>

Thanks for having a look. I'll drop the proposal, and bring it up again  
only if I find a compelling, different use-case in future.

-- ams
