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:
- name: Install policy-rc.d
copy: src=policy-rc.d dest=/usr/sbin/policy-rc.d mode=0755
- name: Install packages
apt: pkg=$item state=installed
with_items: [ git, vim, … ]
- name: Remove policy-rc.d
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:
https://github.com/ansible/ansible/pull/3820
With my proposed module, one could do something like this:
- name: Do we need to install anything?
apt_wouldinstall: pkg=$item
with_items: packages_needed
register: pkglist
- name: Install policy-rc.d if needed
copy: …
when: pkglist.changed
- apt: …
notify:
- 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