Issue using apt with prefix

I am using a third party yaml file to load in php packages (the yaml file can't really change) using a prefix on apt. 

# doesn't work

- name: PHP | MAIN | Install php packages - intl1
  apt: >
    pkg=php5-{{ item }}
    state=latest
  with_items: 
    - cli
    - intl
    - mcrypt
    - curl
  sudo: yes

# error

failed: [localhost] => (item=cli,intl,mcrypt,curl) => {"failed": true, "item": "cli,intl,mcrypt,curl"}
msg: No package matching 'intl' is available

# works

- name: PHP | MAIN | Install php packages - intl2
  apt: >
    pkg=php5-{{ item }}
    state=latest
  with_items: 
    - intl
    - mcrypt
    - curl
  sudo: yes

# in a perfect world (works)

One possible solution is to add a pkg_prefix option to the apt and yum modules.

Don’t prefix it for now and please make sure there is an open ticket, we can easily template the series prior to listification.

The linked commit is, I am pretty sure, not directly related.

– Michael

For completeness, posted at https://github.com/ansible/ansible/issues/5166

If you really don’t want to expand all your package names, something like this may work for you:

  • name: set apache module package prefix
    set_fact: apache_mod_prefix=libapache2-mod-
  • name: install additional modules
    apt: pkg=“{{ apache_mod_prefix }}{{ modules|join(‘,’ + apache_mod_prefix) }}”

(where modules is an array of package suffixes)