Apply Task for one Host

44 views
Skip to first unread message

Dennis Klein

unread,
Mar 2, 2017, 8:02:54 AM3/2/17
to Ansible Project
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.

Kai Stian Olstad

unread,
Mar 2, 2017, 12:02:02 PM3/2/17
to ansible...@googlegroups.com
- 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
---
packages_to_install_on_jenkins:
- <package one>
- <package two>


The in the role you could do this.

- name: Install some packages needed for Jenkins build
package:
name: "{{ item }}"
with_items: "{{ packages_to_install_on_jenkins }}"

I hope this gives you an idea of how you can solve it in Ansible.

--
Kai Stian Olstad

Dennis Klein

unread,
Mar 14, 2017, 6:11:53 AM3/14/17
to Ansible Project, ansible-pr...@olstad.com
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?

Pshem Kowalczyk

unread,
Mar 14, 2017, 3:23:06 PM3/14/17
to ansible...@googlegroups.com
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


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e7065861-3679-407b-ad61-94f0eb04d0f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages