# Apply Task for one Host

**URL:** <https://forum.ansible.com/t/apply-task-for-one-host/23862>\
**Category:** Ansible Project\
**Created:** [March 2, 2017, 10:27am UTC](https://forum.ansible.com/t/apply-task-for-one-host/23862 "2017-03-02T10:27:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dennis\_Klein](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@Dennis\_Klein](https://forum.ansible.com/u/Dennis_Klein)\
**Post date:** [March 2, 2017, 10:27am UTC](https://forum.ansible.com/t/apply-task-for-one-host/23862/1 "2017-03-02T10:27:30Z")

</div>

Hello,

i’m not sure if i understand the Ansible structure correctly and if Ansible is the best solution for us.

Our scenario: We are a webhosting company with about 200 VMs (and counting) with mostly individual websites.  
We also have 4 server farms where multiple VMs serve one website. (3x Webserver, 2x Varnish, 2x DB, etc)

We have started to use Ansible and are now at a point where the best practices from the docs are not usable.

An example for the problem: We have a Jenkins-Server in evey server farm. So we use a Jenkins Role to install it.  
But every instance needs different packages installed for Jenkins to build the software on it.  
So the Task for Ansible to do is to install one package on one Host.

I simply can do that in Puppet or Saltstack, but in Ansible i can’t apply a task to a Host as i know.  
How am i supposed to organize this situation?

I think it is not meant to have a role that is only used once or a playbook for every host.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 2, 2017, 5:01pm UTC](https://forum.ansible.com/t/apply-task-for-one-host/23862/2 "2017-03-02T17:01:48Z")

</div>

- name: Install a package on one host  
&nbsp;&nbsp;&nbsp;package:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: \<some package\>  
&nbsp;&nbsp;&nbsp;when: inventory\_hostname == 'host.example.com'

A better way might be to set a variable in host\_vars/host.example.com.yml

---

<div class="post-metadata">

**Author:** ![Dennis\_Klein](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@Dennis\_Klein](https://forum.ansible.com/u/Dennis_Klein)\
**Post date:** [March 14, 2017, 10:11am UTC](https://forum.ansible.com/t/apply-task-for-one-host/23862/3 "2017-03-14T10:11:53Z")

</div>

Having one file with tasks for all hosts is worse than having one file for each host, but i already have a host\_vars file for every host.

Why do i need a different file to configure a host in another directory?

That makes ansible pretty hard for other contributors to understand, if one host get’s it’s tasks and configuration from different files.

Puppet has just one file for each host where every configuration is in!

Jenkins was just an example, this is a general problem of the design of Ansible.

Is there any solution for this or is Ansible just not usable if you need individual settings for hosts outside of the scope of your roles?

---

<div class="post-metadata">

**Author:** ![Pshem\_Kowalczyk](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@Pshem\_Kowalczyk](https://forum.ansible.com/u/Pshem_Kowalczyk)\
**Post date:** [March 14, 2017, 7:22pm UTC](https://forum.ansible.com/t/apply-task-for-one-host/23862/4 "2017-03-14T19:22:41Z")

</div>

If the requirements per host are different you can do it two ways:

1. Create a role per host
2. Split your current roles into ‘generic’ that are applicable to all hosts and ‘specific’ that only apply to given hosts

It’s probably easier to have a playbook per host then trying to coerce a single playbook and and a single role to do multiple things.

kind regards  
Pshem
