2
votes

When doing a task like this in order to install local packages (a la yum localinstall):

- name: Install local packages
  yum:
    name="/my/path/{{ item }}"
    state=installed
  with_items: list_of_packages

Where list_of_packages is defined in vars/main.yml as:

---
list_of_packages:
  - package1.rpm
  - package2.rpm
  ...    

Yum tries to be smart and put all items in one command but ends only adding the path to the first package:

REMOTE_MODULE yum name="/my/path/package1.rpm,package2.rpm" state=installed

And obviously fails not finding the second package

I've tried adding the path inside like: {{ "/my/path/"+item }} and keeps doing the same.

Is there a way besides duplicating "list_of_packages" with the base path added? (workaround i'm using)

EDIT: Detailed test playbook (ansible version 1.9.2):

# cat playbooks/testlocalinstall.yml
---
- hosts: all:!localhost

  vars:

    list_of_packages:
      - oracleasmlib-2.0.4-1.el6.x86_64.rpm
      - oracleasm-support-2.1.8-1.el6.x86_64.rpm


  tasks:

    - name: Install Packages
      yum: name=/software/{{ item }} state=installed
      with_items: list_of_packages

Result:

# ansible-playbook playbooks/testlocalinstall.yml -i inventory/myinv -vvv

PLAY [all:!localhost] *********************************************************

GATHERING FACTS ***************************************************************
<testmachine> ESTABLISH CONNECTION FOR USER: root on PORT 22 TO testmachine
<testmachine> REMOTE_MODULE setup
<testmachine> EXEC /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1441783338.15-74757921814888 && echo $HOME/.ansible/tmp/ansible-tmp-1441783338.15-74757921814888'
<testmachine> PUT /tmp/tmp_955vP TO /root/.ansible/tmp/ansible-tmp-1441783338.15-74757921814888/setup
<testmachine> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1441783338.15-74757921814888/setup; rm -rf /root/.ansible/tmp/ansible-tmp-1441783338.15-74757921814888/ >/dev/null 2>&1'
ok: [testmachine]

TASK: [Install Packages] ******************************************************
<testmachine> ESTABLISH CONNECTION FOR USER: root on PORT 22 TO testmachine
<testmachine> REMOTE_MODULE yum name=/software/oracleasmlib-2.0.4-1.el6.x86_64.rpm,oracleasm-support-2.1.8-1.el6.x86_64.rpm state=installed
<testmachine> EXEC /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1441783339.35-66981904309720 && echo $HOME/.ansible/tmp/ansible-tmp-1441783339.35-66981904309720'
<testmachine> PUT /tmp/tmpF0hiqP TO /root/.ansible/tmp/ansible-tmp-1441783339.35-66981904309720/yum
<testmachine> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python -tt /root/.ansible/tmp/ansible-tmp-1441783339.35-66981904309720/yum; rm -rf /root/.ansible/tmp/ansible-tmp-1441783339.35-66981904309720/ >/dev/null 2>&1'
failed: [testmachine] => (item=oracleasmlib-2.0.4-1.el6.x86_64.rpm,oracleasm-support-2.1.8-1.el6.x86_64.rpm) => {"changed": false, "failed": true, "item": "oracleasmlib-2.0.4-1.el6.x86_64.rpm,oracleasm-support-2.1.8-1.el6.x86_64.rpm", "rc": 0, "results": []}
msg: No Package file matching 'oracleasm-support-2.1.8-1.el6.x86_64.rpm' found on system

msg:
No Package file matching 'oracleasm-support-2.1.8-1.el6.x86_64.rpm' found on system

FATAL: all hosts have already failed -- aborting

PLAY RECAP ********************************************************************
           to retry, use: --limit @/root/testlocalinstall.retry

testmachine          : ok=1    changed=0    unreachable=0    failed=1

Adding the path to each package on the list works fine

Thanks.

2

2 Answers

1
votes

I was unable to reproduce this issue:

  • 3 packages where downloaded using --downloadonly yum option ( link )
  • Ansible verbose mode showed the same result - only first package has path prefix, but installation works.

Please try this:

  1. Check you Ansible version - there is a chance that bug exists in versions prior to 1.9.2 ( version I was testing on )

  2. Yum cannot find dependancies for package list you provided - make sure all packages downloaded with yum --downloadonly are in the list. They should be stated explicitly together with target packages.

  3. As a workaround you can create local yum repository using template module, that points to the same folder /my/path/. This repo should be disabled by default. Enable this repo only during yum task with enablerepo ( link )

Here is my playbook:

---
- hosts: all

  vars:

    list_of_packages:
      - nc-1.84-24.el6.x86_64.rpm
      - telnet-0.17-48.el6.x86_64.rpm
      - screen-4.0.3-18.el6.x86_64.rpm


  tasks:

    - name: Install Packages
      yum: name=/vagrant/{{ item }} state=installed
      with_items: list_of_packages

Output:

vagrant@localhost vagrant]$ sudo ansible-playbook -vvv -c local -i "localhost," test.yml

PLAY [all] ********************************************************************

GATHERING FACTS ***************************************************************
<localhost> REMOTE_MODULE setup
<localhost> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1441656987.66-146848178907207 && echo $HOME/.ansible/tmp/ansible-tmp-1441656987.66-146848178907207']
<localhost> PUT /tmp/tmp7TIwxU TO /root/.ansible/tmp/ansible-tmp-1441656987.66-146848178907207/setup
<localhost> EXEC ['/bin/sh', '-c', u'LANG=C LC_CTYPE=C /usr/bin/python /root/.ansible/tmp/ansible-tmp-1441656987.66-146848178907207/setup; rm -rf /root/.ansible/tmp/ansible-    tmp-1441656987.66-146848178907207/ >/dev/null 2>&1']
ok: [localhost]

TASK: [Install Packages] ******************************************************
<localhost> REMOTE_MODULE yum name=/vagrant/nc-1.84-24.el6.x86_64.rpm,telnet-0.17-48.el6.x86_64.rpm,screen-4.0.3-18.el6.x86_64.rpm,lftp-4.0.9-6.el6.x86_64.rpm state=installed
<localhost> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1441656987.78-72871194424865 && echo $HOME/.ansible/tmp/ansible-tmp-1441656987.78-72871194424865']
<localhost> PUT /tmp/tmpTy7Al1 TO /root/.ansible/tmp/ansible-tmp-1441656987.78-72871194424865/yum
<localhost> EXEC ['/bin/sh', '-c', u'LANG=C LC_CTYPE=C /usr/bin/python -tt /root/.ansible/tmp/ansible-tmp-1441656987.78-72871194424865/yum; rm -rf /root/.ansible/tmp/ansible-    tmp-1441656987.78-72871194424865/ >/dev/null 2>&1']
changed: [localhost] => (item=nc-1.84-24.el6.x86_64.rpm,telnet-0.17-48.el6.x86_64.rpm,screen-4.0.3-18.el6.x86_64.rpm,lftp-4.0.9-6.el6.x86_64.rpm) => {"changed": true, "item": "nc-1.84-24.el6.x86_64.rpm,    telnet-0.17-48.el6.x86_64.rpm,screen-4.0.3-18.el6.x86_64.rpm,lftp-4.0.9-6.el6.x86_64.rpm", "msg": "", "rc": 0, "results": ["Loaded plugins: fastestmirror\nSetting up Install Process\nExamining /vagrant/    nc-1.84-24.el6.x86_64.rpm: nc-1.84-24.el6.x86_64\nMarking /vagrant/nc-1.84-24.el6.x86_64.rpm to be installed\nLoading mirror speeds from cached hostfile\n * base: mirror.isoc.org.il\n * epel: mirror.de.    leaseweb.net\n * extras: mirror.isoc.org.il\n * updates: mirror.isoc.org.il\nExamining telnet-0.17-48.el6.x86_64.rpm: 1:telnet-0.17-48.el6.x86_64\nMarking telnet-0.17-48.el6.x86_64.rpm to be     installed\nExamining screen-4.0.3-18.el6.x86_64.rpm: screen-4.0.3-18.el6.x86_64\nMarking screen-4.0.3-18.el6.x86_64.rpm to be installed\nResolving Dependencies\n--> Running transaction check\n--->     Package nc.x86_64 0:1.84-24.el6 will be installed\n---> Package screen.x86_64 0:4.0.3-18.el6 will be installed\n---> Package telnet.x86_64 1:0.17-48.el6 will be installed\n--> Finished Dependency     Resolution\n\nDependencies Resolved\n\n================================================================================\n Package    Arch       Version            Repository                           Size\n================================================================================\nInstalling:\n nc         x86_64     1.84-24.el6        /nc-1.84-24.el6.x86_64          109 k\n screen         x86_64     4.0.3-18.el6       /screen-4.0.3-18.el6.x86_64     795 k\n telnet     x86_64     1:0.17-48.el6      /telnet-0.17-48.el6.x86_64      109 k\n\nTransaction     Summary\n================================================================================\nInstall       3 Package(s)\n\nTotal size: 1.0 M\nInstalled size: 1.0 M\nDownloading Packages:\nRunning     rpm_check_debug\nRunning Transaction Test\nTransaction Test Succeeded\nRunning Transaction\n\r  Installing : nc-1.84-24.el6.x86_64                                        1/3 \n\r  Installing : 1:telnet-    0.17-48.el6.x86_64                                  2/3 \n\r  Installing : screen-4.0.3-18.el6.x86_64                                   3/3 \n\r  Verifying  : screen-4.0.3-18.el6.    x86_64                                   1/3 \n\r  Verifying  : 1:telnet-0.17-48.el6.x86_64                                  2/3 \n\r  Verifying  : nc-1.84-24.el6.    x86_64                                        3/3 \n\nInstalled:\n  nc.x86_64 0:1.84-24.el6                screen.x86_64 0:4.0.3-18.el6           \n  telnet.x86_64 1:0.17-48.el6               \n\nComplete!\n"]}

PLAY RECAP ********************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0
0
votes

In order to use with_items I believe it is expecting a yaml list, not a comma-delimited list.

 name: install local packages   
 yum: name="/my/path/{{ item }}" state=installed  
 with_items:
      - package1.rpm
      - package2.rpm
      - package3.rpm

http://docs.ansible.com/ansible/playbooks_loops.html#standard-loops