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

50 views
Skip to first unread message

Matthew Macdonald-Wallace

unread,
Jan 6, 2015, 8:55:49 AM1/6/15
to ansible...@googlegroups.com
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.

Brian Coca

unread,
Jan 7, 2015, 8:13:00 AM1/7/15
to ansible...@googlegroups.com
IIRC you can use the jenkins web api for listing/installing plugins
(using uri module)

--
Brian Coca

Matthew Macdonald-Wallace

unread,
Jan 9, 2015, 5:08:15 AM1/9/15
to ansible...@googlegroups.com
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 <role>/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

Brian Coca

unread,
Jan 9, 2015, 10:05:48 AM1/9/15
to ansible...@googlegroups.com
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.
> --
> 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/01ed5ce4-9ff8-433a-9cab-078868d2b361%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Brian Coca

Mark Janssen

unread,
Jan 9, 2015, 10:51:10 AM1/9/15
to ansible...@googlegroups.com
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 


For more options, visit https://groups.google.com/d/optout.



--
Mark Janssen  --  maniac(at)maniac.nl
Unix / Linux Open-Source and Internet Consultant
Maniac.nl Sig-IO.nl Vps.Stoned-IT.com

Matthew Macdonald-Wallace

unread,
Jan 12, 2015, 7:11:42 AM1/12/15
to ansible...@googlegroups.com
Thanks both,

I'll have a play with that and see what I can get :)

Matt
Reply all
Reply to author
Forward
0 new messages