Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
solve deprecation warnings for using apt with items
Browse files Browse the repository at this point in the history
  • Loading branch information
mjmeijerman committed Nov 6, 2018
1 parent eaa169d commit 778f577
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
23 changes: 23 additions & 0 deletions filter_plugins/prefix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from ansible import errors
from ansible.module_utils._text import to_text

def prefix(value, prefix):
'''
Prefix each item in a list with a prefix
'''

try:
return prefix + value
except TypeError:
raise errors.AnsibleFilterError('This filter only works on a string, offending value: ' + to_text(value))


class FilterModule(object):
'''
Custom jinja2 filter to prefix a string
'''

def filters(self):
return {
'prefix': prefix,
}
13 changes: 5 additions & 8 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@

- name: Install packages needed to use the deb.sury.org repository
apt:
name: "{{ item }}"
with_items:
- apt-transport-https
- ca-certificates
name: ['apt-transport-https', 'ca-certificates']
state: present

- name: Add the deb.sury.org trusted key
apt_key:
Expand Down Expand Up @@ -114,16 +112,15 @@

- name: Install PHP extensions
apt:
name: "php-{{ item }}"
with_items: "{{ php7_extensions }}"
name: "{{ php7_extensions | map('prefix', 'php-') | list }}"
state: present
notify:
- Restart Apache
- Restart PHP FPM

- name: Install versioned PHP extensions
apt:
name: "php{{ php7_version }}-{{ item }}"
with_items: "{{ php7_versioned_extensions }}"
name: "{{ php7_versioned_extensions | map('prefix', 'php' ~ php7_version ~ '-') | list }}"
notify:
- Restart Apache
- Restart PHP FPM

0 comments on commit 778f577

Please sign in to comment.