yum module localinstall many rpms from directory possible?

953 views
Skip to first unread message

daddyocruzer

unread,
Sep 21, 2017, 2:51:03 PM9/21/17
to Ansible Project
Hello

tasks:
  - name:  yum local install
    yum:  name=/sharedfilesystem/*.rpm  state=present

Our team has several environments that lead up to our production environment, so patches must be applied and tested in one environment at a time (as they exist at a specific version 'point-in-time') so I can't do a blind yum update latest in our production environment -- therefore, I download the latest available at a point-in-time and apply them to each environment only once testing has succeeded in the previous environment.

Can ansible yum module help 'localinstall' patches that have been pre-downloaded?   (I've only seen yum module work with a single rpm)   

Maybe should be using command instead of yum module?

Dick Davies

unread,
Sep 21, 2017, 3:37:25 PM9/21/17
to ansible list
That's fine, look at with_items to get it all done in a single yum transaction.
> --
> 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/103e0a52-c075-4f66-9764-ae1f3372f77c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Kai Stian Olstad

unread,
Sep 21, 2017, 3:50:01 PM9/21/17
to ansible...@googlegroups.com
The name support a list or comma separated listing.

So you could do something like this:

- find:
paths: /sharedfilesystem
patterns: '*.rpm'
register: r

- yum:
name: "{{ r.files | map(attribute='path') | list }}"


--
Kai Stian Olstad

daddyocruzer

unread,
Sep 21, 2017, 8:00:30 PM9/21/17
to Ansible Project
Success !!!! 

Some Learning Assumptions:
=======================

So, this section I think I kinda get - it sets up 'r' to iterate through the 'patterns' matches found beneath 'paths'.

 

 

  - yum: 
       name: "{{ r.files | map(attribute='path') | list }}" 

 

 

This must iterate through each match and install it?    Assumptions:

  • Install must be a default, since there's no sign of it.  
  • map(attribute='path' expands to the absolute path of where the match is? 
    •    if so, why is path singlular here, and 'paths' plural is used above?
    •   how is all this done on a 'name' line?   because default yum behavior is install local...?
  • list iterates through matches registered to 'r' lets yum default install it?

Kai Stian Olstad

unread,
Sep 22, 2017, 3:20:23 AM9/22/17
to ansible...@googlegroups.com
On 22.09.2017 02:00, daddyocruzer wrote:
> Success !!!!
>
> Some Learning Assumptions:
> =======================
>
> So, this section I think I kinda get - it sets up 'r' to iterate
> through
> the 'patterns' matches found beneath 'paths'.

register: r register the output of the find in the variable called r.
r can be anything, like result.

To see what the variable r contains you can use debug.

- debug: var=r

One of the returns is files, files is a list of all files find found.
Each list is a array with a lot of information about the file.

If you only want to show this list you can use debug

- debug: var=r.files


> - yum:
> name: "{{ r.files | map(attribute='path') | list }}"

As you can see if you run the debug above you'll see that each list item
has many attributes, one of them is path.
Map filter gather all of them for each entry in the list r.files.

Map returns a object as you can see with

- debug: var="r.files | map(attribute='path')"

so we need to filter it to something useful, and since the yum module
support list we make it a list.

- debug: var="r.files | map(attribute='path') | list"


Another use of debug is with msg.

- debug: msg="All files in a list - {{ r.files | map(attribute='path') |
list }}"


> This must iterate through each match and install it? Assumptions:
>
> - Install must be a default, since there's no sign of it.
> - map(attribute='path' expands to the absolute path of where the
> match
> is?
> - if so, why is path singlular here, and 'paths' plural is
> used
> above?
> - how is all this done on a 'name' line? because default yum
> behavior is install local...?
> - list iterates through matches registered to 'r' lets yum default
> install it?

I think the above answer all the questions.

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages