collecting "items" across roles and then iterating over them in a handler

Hi all,

We have a number of clients for whom we manage systems using Ansible. I’m fairly new to Ansible however my background is heavy use of Chef and Puppet so I understand most of the concepts.

In order to make our lives easier, we have a central “ansible” git repo containing generic roles. This is then cloned as a submodule into each client repo where we override variables and config files accordingly to make the “generic” roles from the master repo client specific.

One of the roles that we have installs and configures Jenkins CI Server. We have a set of “base” jenkins plugins that we install as part of the Jenkins role, however for some clients we will want to install and configure additional plugins.

Is there any way within Ansible that I can collect a list of these plugins from various roles (git, svn, capistrano etc.) and then have them installed by the Jenkins role?

The current approach is to have a “command” task in each role to execute the jenkins-cli command to install the plugins which seems like a very un-DRY way of doing things.

I’m reasonably happy with Python so I’m happy to write a module if this is what is required, however I’m hoping that this is a solved problem!

Thanks in advance for any help,

Matt

P.S. FWIW, it looks like https://github.com/ansible/ansible/pull/6674 might solve this for me, but it’s not been merged as far as I can tell.

IIRC you can use the jenkins web api for listing/installing plugins
(using uri module)

Hi Bryan and thanks for the reply.

The problem I’m trying to solve is collecting multiple jenkins plugins across roles but only executing the installation of them once.

At the moment, I have to list and then install the plugins in each individual /tasks/main.yml whereas what I’d like to do is something like this:

group_vars/server_type_1

jenkins_modules:

  • git
  • ansiicolor

group_vars/server_type_2
jenkins_modules:

  • svn
  • pipeline

group_vars/all
jenkins_modules:

  • chuck-norris

and then have a handler or similar install the relevant plugins (for example a host in server_type_1 group would have chuck-norris, git and ansiicolor installed, whereas a host in server_type_2 would have chuck-norris, svn and pipeline installed instead).

I hope this makes things a bit clearer.

Matt

name the vars differently so they don't override, then you can
mix/match as you please

type1_jenkins_mods:
- git

type2_jenkins_mods:
    - svn
    - pipeline

common_jenkins_mods:
  - chuck-norris

they you can

with_items: "{{common_jenkins_mods|union(type1_jenkins_mods)}}"

for example.

Note that this only works in 1.7.x and beyond … I just ran it on a host still running 1.6.10 and couldn’t get it to work until upgrading to 1.7.x

Mark

Thanks both,

I’ll have a play with that and see what I can get :slight_smile:

Matt