# How to handle package manager depending installations?

**URL:** <https://forum.ansible.com/t/how-to-handle-package-manager-depending-installations/16513>\
**Category:** Ansible Project\
**Created:** [October 15, 2014, 7:44am UTC](https://forum.ansible.com/t/how-to-handle-package-manager-depending-installations/16513 "2014-10-15T07:44:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomas.lehmann1](https://avatars.discourse-cdn.com/v4/letter/t/e47774/32.png) [@thomas.lehmann1](https://forum.ansible.com/u/thomas.lehmann1)\
**Post date:** [October 15, 2014, 7:44am UTC](https://forum.ansible.com/t/how-to-handle-package-manager-depending-installations/16513/1 "2014-10-15T07:44:31Z")

</div>

Hi,

I would like to know how to organize one task that I can install packages depending on the **ansible\_pkg\_mgr** variable?  
Could you please provide an **example** , if possible?

**Please note** : I know … I can create two tasks with a “when” clause. I have that in place.

Kind regards,  
Thomas

**Example** Dictionary in vars/main.yml:

packages:  
apt:

- exuberant-ctags
- cgdb
- figlet
- scite
- graphviz

yum:

- ctags
- cgdb
- figlet
- graphviz

---

<div class="post-metadata">

**Author:** ![Seth\_Edwards](https://avatars.discourse-cdn.com/v4/letter/s/a88e57/32.png) [@Seth\_Edwards](https://forum.ansible.com/u/Seth_Edwards)\
**Post date:** [October 16, 2014, 2:52am UTC](https://forum.ansible.com/t/how-to-handle-package-manager-depending-installations/16513/2 "2014-10-16T02:52:00Z")

</div>

You might want to have a look at this [http://docs.ansible.com/playbooks\_best\_practices.html#operating-system-and-distribution-variance](http://docs.ansible.com/playbooks_best_practices.html#operating-system-and-distribution-variance)

I think if you separated it this way, it might get rid of the need to define these in vars

---

<div class="post-metadata">

**Author:** ![Igor\_Homyakov](https://avatars.discourse-cdn.com/v4/letter/i/f4b2a3/32.png) [@Igor\_Homyakov](https://forum.ansible.com/u/Igor_Homyakov)\
**Post date:** [October 16, 2014, 5:31am UTC](https://forum.ansible.com/t/how-to-handle-package-manager-depending-installations/16513/3 "2014-10-16T05:31:43Z")

</div>

Hi,

Please have a look at [https://gist.github.com/hostmaster/db37c8e6c2a43997a224](https://gist.github.com/hostmaster/db37c8e6c2a43997a224)

It is not probably what you are looking for exactly, however it is  
very close and it works.  
And I hope the idea is clear.

-- Best, Igor
