Apply Task for one Host

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.

- name: Install a package on one host
   package:
     name: <some package>
   when: inventory_hostname == 'host.example.com'

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

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?

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