From 778f5777dd6c5dd2cc3b084c02d6bd681952f3d6 Mon Sep 17 00:00:00 2001 From: Mark Meijerman Date: Tue, 6 Nov 2018 13:59:57 +0100 Subject: [PATCH] solve deprecation warnings for using apt with items --- filter_plugins/prefix.py | 23 +++++++++++++++++++++++ tasks/main.yml | 13 +++++-------- 2 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 filter_plugins/prefix.py diff --git a/filter_plugins/prefix.py b/filter_plugins/prefix.py new file mode 100644 index 0000000..b37c777 --- /dev/null +++ b/filter_plugins/prefix.py @@ -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, + } diff --git a/tasks/main.yml b/tasks/main.yml index da574ce..25f7ed8 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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: @@ -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