Ansible 2.7, yum and list of packages

Hi,

I’m having a problem installing RPMs using the yum module from a list. Using version:

$ ansible --version
ansible 2.7.6.post0 (stable-2.7 f759b5463b) last updated 2019/01/26 09:42:08 (GMT +000)
python version = 2.7.5 (default, Aug 2 2016, 04:20:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]

When running a playbook as follows, yum installs, but executes a separate “yum install” for each item (which is expected but slow):

  • name: install pre-requisites
    yum:
    name: “{{ item }}”
    state: present
    use_backend: yum
    loop:
  • package1
  • package2
  • package3

However, trying to following the deprecation warning:

[DEPRECATION WARNING]: Invoking “yum” only once while using a loop via squash_actions is deprecated. Instead of using a loop to supply multiple items and specifying name: "{{ item }}", please use name: ['package1', package2', 'package3'] and remove the loop.This feature will be removed in version 2.11. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.

However if I try to do so with:

  • name: install oracle pre-requisites 1
    yum:
    name:
  • package1
  • package2
  • package3

or with

  • name: install oracle pre-requisites 1
    yum:
    name: [package1, package2, package3]

I get the error:

failed: [1.1.1.1] (item=[u’package1’, u’package2’, u’package3’]) => {“changed”: false, “item”: [“package1”, “package2”, “package3”], “msg”: “No Package matching ‘[‘package1’’ found available, installed or updated”, “rc”: 0, “results”: }

The error shows [‘package1’ in quotes which seems to indicate some kind of list miscomprehension?

Can anyone spot what I’m doing wrong.

I’ve tried:

  • with/out quotes
  • inline or box layout yaml form for the list
  • i can install fine via separate yum module calls or using the loop mechanism and by extension manually as one transaction on the host itself.

The documentation and source list this as an example but I get the same errors as above:

- name: Install a list of packages
  yum:
    name:
      - nginx
      - postgresql
      - postgresql-server
    state: present

Can anyone see what I'm doing wrong?

as you mentioned towards the end and how the documentation is how to do it. Giving a list to name is how I do it. In the example oracle prequesites looks like you need two spces after name for reach rpm you are installing.

so like

name:

  • nginx

Jonathan,

Thanks for the idea but that’s not it. I even cut and paste the text from https://docs.ansible.com/ansible/latest/modules/yum_module.html#yum-module:

- name: Install a list of packages
  yum:
    name:
      - nginx
      - postgresql
      - postgresql-server
    state: present

Into my playbook and when I run it I still get:

fatal: [IPADDRESS]: FAILED! => {
    "ansible_facts": {
        "pkg_mgr": "yum"
    },
    "changed": false,
    "invocation": {
        "module_args": {
            "conf_file": null,
            "disable_gpg_check": false,
            "disablerepo": null,
            "enablerepo": null,
            "install_repoquery": true,
            "list": null,
            "name": "['nginx', 'postgresql', 'postgresql-server']",
            "state": "present",
            "update_cache": false
        }
    },
    "msg": "No Package matching '['nginx'' found available, installed or updated",
    "rc": 0,
    "results": []
}

Yet on the machine in question:

# yum search nginx
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
229 packages excluded due to repository priority protections
======================================================== N/S matched: nginx =========================================================
collectd-nginx.x86_64 : Nginx plugin for collectd
munin-nginx.noarch : NGINX support for Munin resource monitoring
nextcloud-nginx.noarch : Nginx integration for NextCloud
nginx-all-modules.noarch : A meta package that installs all available Nginx modules
nginx-filesystem.noarch : The basic directory layout for the Nginx server
nginx-mod-http-geoip.x86_64 : Nginx HTTP geoip module
nginx-mod-http-image-filter.x86_64 : Nginx HTTP image filter module
nginx-mod-http-perl.x86_64 : Nginx HTTP perl module
nginx-mod-http-xslt-filter.x86_64 : Nginx XSLT module
nginx-mod-mail.x86_64 : Nginx mail modules
nginx-mod-stream.x86_64 : Nginx stream modules
owncloud-nginx.noarch : Nginx integration for ownCloud
pcp-pmda-nginx.x86_64 : Performance Co-Pilot (PCP) metrics for the Nginx Webserver
python2-certbot-nginx.noarch : The nginx plugin for certbot
nginx.x86_64 : A high performance web server and reverse proxy server

This still seems to be some kind of bug in yum module parsing the list?

Okay,

I’ve found the problem. I’m running Ansible from source. I recloned the repo into a new directory and now it runs correctly. A git status shows no changes on the problem clone and a diff between the yum modules show no difference, however clearly I introduced a problem somewhere in my original checkout.

Probably should run from binary installation.

Thanks all.