Git Product home page Git Product logo

ansible-role-php-versions's Introduction

Ansible Role: PHP Versions

CI

Allows different PHP versions to be installed when using the geerlingguy.php role (or a similar role). This role was originally built for Drupal VM but was released more generically so others could use an easier mechanism for switching PHP versions.

Requirements

N/A

Role Variables

Available variables are listed below, along with default values (see defaults/main.yml):

php_version: '8.2'

The PHP version to be installed. Any currently-supported PHP major version is a valid option (e.g. 7.4, 8.0, 8.1, or 8.2).

php_versions_install_recommends: false

(For Debian OSes only) Whether to install recommended packages. This is set to no by default because setting it to yes often leads to multiple PHP versions being installed (thus making a bit of a mess) when using repos like Ondrej's PHP PPA for Ubuntu.

Dependencies

  • geerlingguy.php is a soft dependency as the php_version variable is required to be set.
  • geerlingguy.repo-remi, if you're using CentOS or a Red Hat derivative.

Example Playbook

- hosts: webservers
  become: true

  vars:
    php_version: '8.2'

  roles:
    - name: geerlingguy.repo-remi
      when: ansible_os_family == 'RedHat'
    - geerlingguy.php-versions
    - geerlingguy.php

License

MIT / BSD

Author Information

This role was created in 2017 by Jeff Geerling, author of Ansible for DevOps.

ansible-role-php-versions's People

Contributors

chrisdeeming avatar geerlingguy avatar gotmax23 avatar luminouw avatar m-demoraes avatar mikkoc avatar oxyc avatar rockandska avatar steinbrueckri avatar webarchitect609 avatar wells avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ansible-role-php-versions's Issues

Support php version switch for existing setups

I'd like to integrate the necessary steps to support PHP version upgrades for already provisioned systems; without dropping manually in a shell to do the setup.

The error message is helpful enough, that outside some additional checks, should be straightforward.

The operation would result in switching of module 'php' stream 'remi-7.3' to stream
'remi-7.4' Error: It is not possible to switch enabled streams of a module. It is
recommended to remove all installed content from the module, and reset the module
using 'dnf module reset <module_name>' command. After you reset the module, you
can install the other stream

If there's interest to support this functionality in this role, let me know and I'll work on it.

Add support for CentOS 8

It looks like CentOS 8 might require a new package naming convention... see blog post: PHP version 7.4.0 released!.

When I tried to update the tests to use 8 instead of 7 I got:

    TASK [geerlingguy.php : Ensure PHP packages are installed.] ********************
    fatal: [instance]: FAILED! => {"changed": false, "failures": ["No package php-imap available."], "msg": ["Failed to install some of the specified packages"], "rc": 1, "results": []}

And indeed, running yum list available php\* gives me things like:

Last metadata expiration check: 0:11:51 ago on Mon Dec  2 18:35:43 2019.
Available Packages
php.x86_64                                                7.2.11-1.module_el8.0.0+56+d1ca79aa                  AppStream
php-bcmath.x86_64                                         7.2.11-1.module_el8.0.0+56+d1ca79aa                  AppStream
php-cli.x86_64                                            7.2.11-1.module_el8.0.0+56+d1ca79aa                  AppStream
...
php56.x86_64                                              3.0-1.el8.remi                                       remi-safe
php56-build.x86_64                                        3.0-1.el8.remi                                       remi-safe
php56-php.x86_64                                          5.6.40-14.el8.remi                                   remi-safe
...
php73-scldevel.x86_64                                     2.0-1.el8.remi                                       remi-safe
php73-unit-php.x86_64                                     1.13.0-1.el8.remi                                    remi-safe
php73-zephir.noarch                                       0.10.16-1.el8.remi                                   remi-safe
php74.x86_64                                              1.0-1.el8.remi                                       remi-safe
php74-build.x86_64                                        1.0-1.el8.remi                                       remi-safe
php74-php.x86_64                                          7.4.0-1.el8.remi                                     remi-safe
php74-php-ast.x86_64                                      1.0.5-1.el8.remi                                     remi-safe
...

So it seems with the modules/appstream/etc. in CentOS 8, I'll have to do a little work to this role (and probably the main PHP role) to get it to work well with both CentOS 8 and CentOS <= 7.

Using geerlingguy.php-versions prevents overriding geerlingguy.php's php_packages variable

Greetings.

We just found out about and started to test this role alongside your geerlingguy.php role (thanks for these!)

Unfortunately, we've found that this role makes it impossible to customize geerlingguy.php's php_packages variable. I'm fairly sure this isn't a case of us misunderstanding the use or one or both roles, but I guess that's always a possibility ๐Ÿ˜„.

For example, the following variable definition in a playbook works unless the geerlingguy.php-versions role is used:

    # Replace default var with the same list, with mod-php and minus php7.1-fpm.
    php_packages:
      - "php{{ php_version }}"
      - "php{{ php_version }}-apcu"
      - "php{{ php_version }}-cli"
      - "php{{ php_version }}-common"
      - "php{{ php_version }}-curl"
      - "php{{ php_version }}-dev"
      - "php{{ php_version }}-gd"
      - "php{{ php_version }}-imap"
      - "php{{ php_version }}-json"
      - "php{{ php_version }}-mbstring"
      - "php{{ php_version }}-mcrypt"
      - "php{{ php_version }}-opcache"
      - "php{{ php_version }}-sqlite3"
      - "php{{ php_version }}-xml"
      - "php{{ php_version }}-yaml"
      - "libapache2-mod-php{{ php_version }}"

I've created a git repo containing a playbook and Vagrantfile to demonstrate both the working and non-working configurations: https://github.com/ctorgalson/php-versions

No package matching 'php7.3' is available

I getting this error on fresh ubuntu installation on vagrant box. Tried several distribs of ubuntu and debian, different php versions (7.2/7.3/7.4) in php_version and php_default_version_debian, but error is always the same. What can I do to find the reason?

Ability to install specific versions of PHP

Hi,

I just tried this role for the first time and I tried to pin the PHP version to install to 7.1.5 but it looks like the role is unable to install specific versions of PHP.

Trying to do the above produced the following error for me:

No package matching 'php7.1.5' is available

Is this expected?

I was going under the assumption it was able to install a specific version of PHP because one might not want to use 7.1 and have the potential of jumping from 7.1.5 to 7.1.6 without being aware of it (not to mention the potential breaking changes/bugs which might be introduced).

The goal of this role!?

Good day!

Thank you work your work for society!

your role purpose was declared as:

Allows different PHP versions to be installed when using the geerlingguy.php role (or a similar role). This role was originally >built for Drupal VM but was released more generically so others could use an easier mechanism for switching PHP versions.

but we have only one variable to manage versions:

php_version: '7.4'

How, for example, can I install and configure both 7.4 and 8.0 PHP versions on the same PC?

the role always purges other PHP versions:

TASK [geerlingguy.php-versions : Purge PHP version packages (besides the currently chosen php_version).] 
TASK [geerlingguy.php-versions : Also purge php-common package if any versions were just purged.] 

different PHP versions to be installed

What do you mean by 'different'? It would be great if you clarify and provide some examples how to use this role along with your 'pair ''PNP' role.

All the best!

Task adding the Ondrej Sury's apt key tries to download it every time

Hello here,

I have a question regarding the use of the apt_key module when sitting up in a corporate restricted environment.

The documentation of the module specifies that apt_key should only try and download the key if it really needs it. On the machines I plan to use this role with restricted connectivity to the outside world, the key is shipped beforehand by our Ansible controllers and added to the hosts.

Since the key_id isn't specified in the task, and even though the key actually exists on the system, it tries to download it and fails every time at this stage.

Question(s) :

  • Would it be relevant to add Ondrej Sury's key ID to the role / task ? And thus preventing the systematic download if unnecessary.
  • If managing and updating the ID is cumbersome, would adding another condition (eg. when: ansible_distribution == "Debian" and skip_apt_key_tasks == True) be an option that you'd consider ?

Reality is the majority of people using this won't ever face this issue, but there are still lots of corporate networks well buried behind a shitload of proxies and security decisions that won't be allowed directly on the internet (I know, not really "cloud" friendly) and most existing roles don't even take into account the possibility of a single proxy :(

Let me know what you think !

Thanks

ansible-lint still sees errors

@geerlingguy , please, check out PR #61 which fixes the following errors and warnings by ansible-lint:

  • error: internal-error the role 'geerlingguy.repo-remi' was not found in...
  • error: syntax-check 'src' is not a valid attribute for a Play
  • warning: [line-length] line too long (173 > 120 characters)

P.S.: And thanks for applying my PR #55 ; now I will mark my fork as 'deprecated' and return control to 'the mothership' :)

Add support for discontinued versions of PHP

I know versions of PHP have had support dropped so you have drawn a line in the sand to not support them.

I am using DrupalVM and trying to align as closely with a client site is not always possible using stable versions.

Would it be possible add in support for unsupported versions of Drupal so that we can be working on the same version of PHP as client sites.

This could be added as an unsupported enhancement. For me if 5.5 can be added it would make this much easier for me, as I don't have to stop the development team from using 5.6 functionality.

Thanks.

php-versions 5.6 still installs php 7.2

I was trying to install php 5.6 in a Vagrant debian/contrib-jessie64 machine. I set the variable to 5.6 in the defaults/main.yml in the php-versions role.
This sets all the correct variables. But when install with the role php i still got php 7.2. I did some debugging (ansible -v) and found this:

TASK [geerlingguy.php : Ensure PHP packages are installed.] ********************
changed: [default] => (item=[u'php5.6', u'php5.6-apcu', u'php5.6-cli', u'php5.6-common', u'php5.6-curl', u'php5.6-dev', u'php5.6-fpm', u'php5.6-gd', u'php5.6-imap', u'php5.6-json', u'php5.6-mbstring', u'php5.6-mcrypt', u'php5.6-opcache', u'php5.6-sqlite3', u'php5.6-xml', u'php5.6-yaml']) => {"cache_update_time": 1514993379, "cache_updated": false, "changed": true, "item": ["php5.6", "php5.6-apcu", "php5.6-cli", "php5.6-common", "php5.6-curl", "php5.6-dev", "php5.6-fpm", "php5.6-gd", "php5.6-imap", "php5.6-json", "php5.6-mbstring", "php5.6-mcrypt", "php5.6-opcache", "php5.6-sqlite3", "php5.6-xml", "php5.6-yaml"], "stderr": "Reading changelogs...\n\rExtracting templates from packages: 32%\rExtracting templates from packages: 64%\rExtracting templates from packages: 96%\rExtracting templates from packages: 100%\n", "stderr_lines": ["Reading changelogs...", "", "Extracting templates from packages: 32%", "Extracting templates from packages: 64%", "Extracting templates from packages: 96%", "Extracting templates from packages: 100%"], "stdout": "Reading package lists...\nBuilding dependency tree...\nReading state information...\nThe following extra packages will be installed:\n autoconf automake autopoint autotools-dev build-essential debhelper dh-php\n dpkg-dev fakeroot fontconfig-config fonts-dejavu-core g++ g++-4.9 gettext\n intltool-debian libalgorithm-diff-perl libalgorithm-diff-xs-perl\n libalgorithm-merge-perl libapparmor1 libargon2-0 libasprintf-dev\n libc-client2007e libc-dev-bin libc6-dev libcroco3 libcurl3 libdpkg-perl\n libfakeroot libfile-fcntllock-perl libfontconfig1 libgd3 libgettextpo-dev\n libgettextpo0 libglib2.0-0 libglib2.0-data liblist-moreutils-perl\n libltdl-dev libltdl7 libmail-sendmail-perl libmcrypt4 libpcre16-3 libpcre3\n libpcre3-dev libpcre32-3 libpcrecpp0v5 libsodium18 libssl-dev libssl-doc\n libssl1.0.2 libstdc++-4.9-dev libsys-hostname-long-perl libtool\n libunistring0 libvpx1 libxpm4 libxslt1.1 libyaml-0-2 linux-libc-dev\n manpages-dev mlock php-apcu-bc php-common php-pear php5.6-readline\n php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-phpdbg\n php7.2-readline pkg-php-tools po-debconf shared-mime-info shtool\n xdg-user-dirs xml2 zlib1g-dev\nSuggested packages:\n autoconf-archive gnu-standards autoconf-doc dh-make debian-keyring\n g++-multilib g++-4.9-multilib gcc-4.9-doc libstdc++6-4.9-dbg gettext-doc\n uw-mailutils glibc-doc libgd-tools libtool-doc libmcrypt-dev mcrypt\n libstdc++-4.9-doc automaken gfortran fortran95-compiler gcj-jdk php-gd\n libmail-box-perl\nRecommended packages:\n php-readline\nThe following NEW packages will be installed:\n autoconf automake autopoint autotools-dev build-essential debhelper dh-php\n dpkg-dev fakeroot fontconfig-config fonts-dejavu-core g++ g++-4.9 gettext\n intltool-debian libalgorithm-diff-perl libalgorithm-diff-xs-perl\n libalgorithm-merge-perl libapparmor1 libargon2-0 libasprintf-dev\n libc-client2007e libc-dev-bin libc6-dev libcroco3 libcurl3 libdpkg-perl\n libfakeroot libfile-fcntllock-perl libfontconfig1 libgd3 libgettextpo-dev\n libgettextpo0 libglib2.0-0 libglib2.0-data liblist-moreutils-perl\n libltdl-dev libltdl7 libmail-sendmail-perl libmcrypt4 libpcre16-3\n libpcre3-dev libpcre32-3 libpcrecpp0v5 libsodium18 libssl-dev libssl-doc\n libssl1.0.2 libstdc++-4.9-dev libsys-hostname-long-perl libtool\n libunistring0 libvpx1 libxpm4 libxslt1.1 libyaml-0-2 linux-libc-dev\n manpages-dev mlock php-apcu php-apcu-bc php-common php-pear php-yaml php5.6\n php5.6-cli php5.6-common php5.6-curl php5.6-dev php5.6-fpm php5.6-gd\n php5.6-imap php5.6-json php5.6-mbstring php5.6-mcrypt php5.6-opcache\n php5.6-readline php5.6-sqlite3 php5.6-xml php7.2-cli php7.2-common\n php7.2-json php7.2-opcache php7.2-phpdbg php7.2-readline pkg-php-tools\n po-debconf shared-mime-info shtool xdg-user-dirs xml2 zlib1g-dev\nThe following packages will be upgraded:\n libpcre3\n1 upgraded, 92 newly installed, 0 to remove and 2 not upgraded.\nNeed to get 59.6 MB of archives.\nAfter this operation, 174 MB of additional disk space will be used.

As you can see, there are still PHP 7.2 packages installed altough ansible only passes PHP 5.6 packages to the installer.
I ran only the php-versions role and went on installing the PHP packages one by one. I found out the php-apcu package is the problem.
Manually running APT will give you this:

vagrant@contrib-jessie:~$ sudo apt install php5.6-apcu
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'php-apcu' instead of 'php5.6-apcu'
The following extra packages will be installed:
libargon2-0 libsodium18 php-apcu-bc php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-phpdbg php7.2-readline
Suggested packages:
php-gd php-pear
The following NEW packages will be installed:
libargon2-0 libsodium18 php-apcu php-apcu-bc php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-phpdbg php7.2-readline
0 upgraded, 10 newly installed, 0 to remove and 3 not upgraded.
Need to get 3721 kB of archives.
After this operation, 16.8 MB of additional disk space will be used.

I have not tested this on any other platform, maybe it is only Debian. Should the php5.6-apcu be removed from the list? It does not seem to exist anymore. I could submit a pull, but i rather ask for advice first.

Playbook:

  • hosts: all
    remote_user: vagrant
    become: true
    roles:
    - geerlingguy.php-versions
    - geerlingguy.php

Vagrantfile:

Vagrant.configure("2") do |config|
config.vm.box = "debian/contrib-jessie64"
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
end
config.vm.provision "ansible" do |ansible|
ansible.playbook = "ansible/webserver.yml"
ansible.verbose = "v"
end
end

Host OS: Fedora 27
Guest OS: Debian Jessie

Ensure dnf-plugins are installed on CentOS 8+.

Task "Ensure dnf-plugins are installed on CentOS 8+" is ran on RHEL8.
But "dnf config-manager --set-enabled powertools" fails because powertools is unavailable on RHEL8.

Displayed Error :
Error: No matching repo to modify: powertools.\nThe operation would result in switching of module 'php' stream '7.2' to stream 'remi-7.4'\nError: It is not possible to switch enabled streams of a module unless explicitly enabled via configuration option module_stream_switch.\nIt is recommended to rather remove all installed content from the module, and reset the module using 'dnf module reset <module_name>' command. After you reset the module, you can install the other stream.

[Enhancement] Grab old config values from past install to use in new version

Was using this to upgrade a site's php version from 7.1 to 7.3. Ran into some issues where php fpm default values weren't as expected. Had to dig through old php's install configs to get what was needed to be updated. Would be great if this installed new php versions with same config values if php already existed and the config values are relevant to new install.

PHP 7.3 CLI gets installed if purging 7.2 and installing 7.1

This is a weird corner case that currently only seems to occur if you already have PHP 7.2 installed (as the geerlingguy/drupal-vm base box for Vagrant does), and you set php_version to 7.1... see geerlingguy/drupal-vm#1963 for all the gory details.

In local testing, adding the following task in tasks/setup-Debian.yml seems to fix the issue:

- name: Purge PHP version packages (besides the currently chosen php_version).
  apt:
    name: "{{ php_versions_debian | reject('search', 'php' ~ php_version) | list }}"
    state: absent
    purge: true
    force: true
  register: php_version_purge

- name: Also purge php-common package if any versions were just purged.
  apt:
    name: php-common
    state: absent
    purge: true
    force: true
  when: php_version_purge.changed | bool

using php_version: '7.4' installs php 8.0

Hello,

I am trying to install php 7.4 on a new debian 10 server. Whenever I use php_version: '7.4' and php_default_version_debian: '7.4' for the ansible-role-php role it installs the version 8.0.

Am I missing a configuration somewhere?

Thank you in advance.

Greetings,
Khallouki

[ERROR] Could not find the requested service php7.4-fpm

(probably needs a better title.

this only happens when php_version is not 8.0

Setup:

  • vagrant with box = "debian/buster64"

both playbooks:

  roles:
    - geerlingguy.php-versions
    - geerlingguy.php

Playbook 1 - works as advertised:

  vars:
    php_version: '7.4'

Playbook 2 - error from title:

  vars:
    php_version: '7.4'
    php_packages:
      - php-cli
      - php-fpm
      - php-zip
      - php-xml
      - php-curl
      - php-ldap
      - php-json
      - php-mbstring

I'm not sure if this is related to this role or the php role, due to the fact that the php role is installing the latest php packages.

so, a combination of php_packages and the role php-versions with a php version other than 8.0 results in a error.

Fails on RHEL 8 when attempting to enable the PowerTools repo

The task to enable the PowerTools repo (below) does not work on RHEL 8, but it is marked warn: false so errors occur later if attempting to install a PHP module that is in powertools.

  - name: Enable DNF module for CentOS 8+.
    shell: |
      dnf config-manager --set-enabled powertools
      dnf module enable -y php:remi-{{ php_version }}
    args:
      warn: false
    register: dnf_module_enable
    changed_when: "'Nothing to do' not in dnf_module_enable.stdout"

'Could not get lock' error in Purge PHP version packages step

Hi!

I have some strange behaviour with the role. Sometimes works well and sometimes gives this error executing the Purge PHP version packages step:

failed: [default] (item=[u'php5.6-common', u'php7.0-common', u'php7.2-common', u'php7.3-common']) => {"changed": false, "item": ["php5.6-common", "php7.0-common", "php7.2-common", "php7.3-common"], "msg": "'apt-get remove 'php7.0-common' 'php7.2-common'' failed: E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)\nE: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?\n", "rc": 100, "stderr": "E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)\nE: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?\n", "stderr_lines": ["E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)", "E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?"], "stdout": "", "stdout_lines": []}

Some info about the environment:

  • Ansible 2.7.1
  • Ansible PHP-versions role 2.1.5
  • Provisioned machine is Ubuntu 16.04
  • PHP version is 7.1

Maybe this error is related to issue #24

Thanks for your great work!

Ansible 2.7 emits DEPRECATION WARNING on 'Purge PHP version packages' task

From a recent Drupal VM build on Ansible 2.7.0:

TASK [geerlingguy.php-versions : Purge PHP version packages.] ******************
[DEPRECATION WARNING]: Invoking "apt" 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: [u'php5.6-common', 
u'php7.0-common', u'php7.1-common', u'php7.2-common']` 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.
ok: [drupalvm] => (item=[u'php5.6-common', u'php7.0-common', u'php7.2-common'])

The problem here is, the with_items loop is not necessary for the apt name parameter, but it is used as part of the when clause to identify which items the apt module should operate on...

Here's the full task:

# PHP package purges.
- name: Purge PHP version packages.
  apt:
    name: "{{ item }}"
    state: absent
    purge: true
    force: true
  with_items:
    - php5.6-common
    - php7.0-common
    - php7.1-common
    - php7.2-common
  when: "'php' + php_version not in item"

[question] problems with ppa

question, what I am doing wrong (Ubuntu on hosts)

playbook:

- hosts: webservers
  roles:
    - geerlingguy.php
    - geerlingguy.php-versions

vars:

php_version: "7.1"
php_default_version_debian: "7.1"
php_versions_install_recommends: true
php_packages_state: "latest"
php_packages_extra:
  - php-mcrypt
  - php{{ php_version }}-mysql
  - php{{ php_version }}-intl
  - php{{ php_version }}-zip
  - php{{ php_version }}-pdo
  - php{{ php_version }}-soap
  - php{{ php_version }}-mbstring
  - php{{ php_version }}-bcmath
  - php{{ php_version }}-gd
php_enable_php_fpm: true

and I got error:
image

and when I am checking possible php to install there are only php7.0-xxxxx if I am using xenial
php7.2 if using bionic64. (no matter if I use php_packages_state: "latest" or not)

Role overwrites gerrlingguy.php's php_packages

Description

When using this role, the php_packages variable is completely overridden by the role's defaults.

For example, this is in my group_vars:

php_packages:
  - php
  - php-fpm
  - php-cli
  - php7.1-common
  - php-gd
  - php-mbstring
  - php-xml
  - php-memcached
  - php7.1-opcache
  - php-sqlite3
  - php7.1-mysql
  - php7.1-curl

When using this role, however, the task reads:

TASK [geerlingguy.php : Ensure PHP packages are installed.] ******************** ok: [45.56.85.211] => (item=[u'php7.1', u'php7.1-apcu', u'php7.1-cli', u'php7.1-common', u'php7.1-curl', u'php7.1-dev', u'php7.1-fpm', u'php7.1-gd', u'php7.1-imap', u'php7.1-json', u'php7.1-mbstring', u'php7.1-mcrypt', u'php7.1-opcache', u'php7.1-sqlite3', u'php7.1-xml', u'php7.1-yaml'])

This corresponds to the defaults provided by this role for my platform: https://github.com/geerlingguy/ansible-role-php-versions/blob/master/vars/Debian.yml

The problem appears to be in the set_fact that does not check if the variable exists elsewhere first.

This is a bit of a problem for database backed sites, since we can't install mysql using the method familiar when only using the php role, and not this role as well.

Workaround

Instead of overriding the php_packages variable, use php_packages_extra

Proposed solution

Either document that this role overrides php_packages completely, or split off the set_fact to account for a preexisting definition.

php8.0-json is part of PHP

Since PHP8 php-json is now part of php, so when installing this package gives an error.

fatal: [host1]: FAILED! => {"cache_update_time": 1630450023, "cache_updated": false, "changed": false, "msg": "'/usr/bin/apt-get -y -o \"Dpkg::Options::=--force-confdef\" -o \"Dpkg::Options::=--force-confold\"      install 'php8.0' 'php8.0-apcu' 'php8.0-cli' 'php8.0-common' 'php8.0-curl' 'php8.0-dev' 'php8.0-fpm' 'php8.0-gd' 'php8.0-imap' 'php8.0-json' 'php8.0-mbstring' 'php8.0-opcache' 'php8.0-sqlite3' 'php8.0-xml' 'php8.0-yaml' -o APT::Install-Recommends=yes' failed: E: Package 'php8.0-json' has no installation candidate\n", "rc": 100, "stderr": "E: Package 'php8.0-json' has no installation candidate\n", "stderr_lines": ["E: Package 'php8.0-json' has no installation candidate"], "stdout": "Reading package lists...\nBuilding dependency tree...\nReading state information...\nPackage php8.0-json is a virtual package provided by:\n  php8.0-phpdbg 8.0.10-1+ubuntu20.04.1+deb.sury.org+1\n  php8.0-fpm 8.0.10-1+ubuntu20.04.1+deb.sury.org+1\n  php8.0-cli 8.0.10-1+ubuntu20.04.1+deb.sury.org+1\n  php8.0-cgi 8.0.10-1+ubuntu20.04.1+deb.sury.org+1\n  libphp8.0-embed 8.0.10-1+ubuntu20.04.1+deb.sury.org+1\n  libapache2-mod-php8.0 8.0.10-1+ubuntu20.04.1+deb.sury.org+1\n\n", "stdout_lines": ["Reading package lists...", "Building dependency tree...", "Reading state information...", "Package php8.0-json is a virtual package provided by:", "  php8.0-phpdbg 8.0.10-1+ubuntu20.04.1+deb.sury.org+1", "  php8.0-fpm 8.0.10-1+ubuntu20.04.1+deb.sury.org+1", "  php8.0-cli 8.0.10-1+ubuntu20.04.1+deb.sury.org+1", "  php8.0-cgi 8.0.10-1+ubuntu20.04.1+deb.sury.org+1", "  libphp8.0-embed 8.0.10-1+ubuntu20.04.1+deb.sury.org+1", "  libapache2-mod-php8.0 8.0.10-1+ubuntu20.04.1+deb.sury.org+1", ""]}

This role overrides php_packages, which is also used in geerlingguy.php

Our playbook has the following config defined:

vars:
  php_packages:
    - php{{ php_version }}-intl
    - php{{ php_version }}-zip
    ...
roles:
  - geerlingguy.php-versions
  - geerlingguy.php
  ...

When we run the playbook, the php packages we were specifying were not being installed. We found that geerlingguy.php_versions was setting php_packages to that role's default value, and geerlingguy.php was then using this default over our user-specified value. We tried specifying php_packages in vars as above, in a vars file, and inline with the role itself (- { role: geerlingguy.php, vars: php_packages: ... }), but nothing changed.

The only way we could work around this was by defining the php_packages variable in a new role after php-versions had run:

vars:
  php_packages:
    - php{{ php_version }}-cli
    - php{{ php_version }}-zip
    ...
roles:
  - geerlingguy.php-versions
  - php-packages
  - geerlingguy.php
  ...

... with the php-packages role containing the following ...

set_fact: php_packages="{{ custom_php_packages }}"

Firstly, is there something I'm doing wrong in specifying the php_packages variable? If it's something I've done wrong, what should I change and why is this particular use case different to others?

Is it just a case of renaming this role's (internal only?) variable to something more unique? If so, I'm happy to provide a PR.

Thanks!

Cannot get key from keyserver ppa:ondrej/php.

setup-Debien.yml contains the following step:

- name: Add repository for PHP versions (Ubuntu).
  apt_repository: repo='ppa:ondrej/php'
  when: ansible_distribution == "Ubuntu"

When I run Drupal VM it fails on this step with the message:

TASK [geerlingguy.php-versions : Add repository for PHP versions (Ubuntu).] ****
fatal: [ama-d8.local]: FAILED! => {"changed": false, "cmd": "apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 14AA40EC0831756756D7F66C4F4EA0AAE5267A6C", "msg": "gpg: requesting key E5267A6C from hkp server keyserver.ubuntu.com\ngpg: no valid OpenPGP data found.\ngpg: Total number processed: 0\ngpg: keyserver communications error: keyserver helper general error\ngpg: keyserver communications error: unknown pubkey algorithm\ngpg: keyserver receive failed: unknown pubkey algorithm", "rc": 2, "stderr": "gpg: requesting key E5267A6C from hkp server keyserver.ubuntu.com\ngpg: no valid OpenPGP data found.\ngpg: Total number processed: 0\ngpg: keyserver communications error: keyserver helper general error\ngpg: keyserver communications error: unknown pubkey algorithm\ngpg: keyserver receive failed: unknown pubkey algorithm\n", "stderr_lines": ["gpg: requesting key E5267A6C from hkp server keyserver.ubuntu.com", "gpg: no valid OpenPGP data found.", "gpg: Total number processed: 0", "gpg: keyserver communications error: keyserver helper general error", "gpg: keyserver communications error: unknown pubkey algorithm", "gpg: keyserver receive failed: unknown pubkey algorithm"], "stdout": "Executing: /tmp/tmp.pkdCtPMbvj/gpg.1.sh --recv-keys\n--keyserver\nhkp://keyserver.ubuntu.com:80\n14AA40EC0831756756D7F66C4F4EA0AAE5267A6C\ngpgkeys: key 14AA40EC0831756756D7F66C4F4EA0AAE5267A6C can't be retrieved\n", "stdout_lines": ["Executing: /tmp/tmp.pkdCtPMbvj/gpg.1.sh --recv-keys", "--keyserver", "hkp://keyserver.ubuntu.com:80", "14AA40EC0831756756D7F66C4F4EA0AAE5267A6C", "gpgkeys: key 14AA40EC0831756756D7F66C4F4EA0AAE5267A6C can't be retrieved"]}

I don't know enough about keyservers, so maybe it's temporarily down or something. I just started getting this today.

https://launchpad.net/~ondrej/+archive/ubuntu/php/+packages is the server? It seems accessible, but I'm not really sure how to check.

New issue "Depends: libgd3 (>= 2.1.1)"

PHP5.6 was working last night, this morning it is falling.

failed: [42.42.42.42] (item=[u'php5.6', u'php5.6-apcu', u'php5.6-cli', u'php5.6-common', u'php5.6-curl', u'php5.6-dev', u'php5.6-fpm', u'php5.6-gd', u'php5.6-imap', u'php5.6-json', u'php5.6-mbstring', u'php5.6-mcrypt', u'php5.6-opcache', u'php5.6-sqlite3', u'php5.6-xml', u'php5.6-yaml']) => {"cache_update_time": 1517836912, "cache_updated": false, "changed": false, "item": ["php5.6", "php5.6-apcu", "php5.6-cli", "php5.6-common", "php5.6-curl", "php5.6-dev", "php5.6-fpm", "php5.6-gd", "php5.6-imap", "php5.6-json", "php5.6-mbstring", "php5.6-mcrypt", "php5.6-opcache", "php5.6-sqlite3", "php5.6-xml", "php5.6-yaml"], "msg": "'/usr/bin/apt-get -y -o \"Dpkg::Options::=--force-confdef\" -o \"Dpkg::Options::=--force-confold\"     
install 'php5.6' 'php5.6-apcu' 'php5.6-cli' 'php5.6-common' 'php5.6-curl' 'php5.6-dev' 'php5.6-fpm' 'php5.6-gd' 'php5.6-imap' 'php5.6-json' 'php5.6-mbstring' 'php5.6-mcrypt' 'php5.6-opcache' 'php5.6-sqlite3' 'php5.6-xml' 'php5.6-yaml' -o APT::Install-Recommends=no' failed: E: Unable to correct problems, you have held broken packages.\n", "rc": 100, "stderr": "E: Unable to correct problems, you have held broken packages.\n", "stderr_lines": ["E: Unable to correct problems, you have held broken packages."], "stdout": "Reading package lists...\nBuilding dependency tree...\nReading state information...\nSome packages could not be installed. This may mean that you have\nrequested an impossible situation or if you are using the unstable\ndistribution that some required packages have not yet been created\nor been moved out of Incoming.\nThe following information may help to resolve the situation:\n\nThe following packages have unmet dependencies:\n php5.6-gd : Depends: libgd3 (>= 2.1.1) but it is not going to be installed\n", "stdout_lines": ["Reading package lists...", "Building dependency tree...", "Reading state information...", "Some packages could not be installed. This may mean that you have", "requested an impossible situation or if you are using the unstable", "distribution that some required packages have not yet been created", "or been moved out of Incoming.", "The following information may help to resolve the situation:", "", "The following packages have unmet dependencies:", " php5.6-gd : Depends: libgd3 (>= 2.1.1) but it is not going to be installed"]}

Trying to install manually it seems something else was not updated.

sudo apt-get install libgd3
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libgd3 : Depends: libwebp5 (>= 0.4.3) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

Add variable to toggle removal of older PHP verions

My organization finds it very useful to run two versions of PHP-FPM. This role nearly accomplishes this goal, but the purge task in setup-Debian.yml stops that from working for us.

Would you be willing to allow a when condition to be added to toggle that task? Maybe call it php_remove_old_versions? Not sure how this would work for the RedHat side of things, though.

Support PHP 7.2

It seems ondrej's repo supports PHP 7.2 now.

  • Add php 7.2 to Debian purge task
  • Omit php-mcrypt on 7.2+

Working on this now

switching of module 'php' stream '7.2' to stream 'remi-7.4

Hello,

I encounter an issue on CentOS 8 where I wanted to use a 7.4 version of the repo remi.
and I got this error:

TASK [galaxy-php-versions : Enable DNF module for CentOS 8+.] ***********************************************************************
fatal: [orc-admin.test]: FAILED! => changed=true
  cmd: |-
    dnf config-manager --set-enabled PowerTools
    dnf module enable -y php:remi-7.4
  delta: '0:00:13.355465'
  end: '2020-09-09 14:34:02.534515'
  msg: non-zero return code
  rc: 1
  start: '2020-09-09 14:33:49.179050'
  stderr: |-
    The operation would result in switching of module 'php' stream '7.2' to stream 'remi-7.4'
    Error: It is not possible to switch enabled streams of a module.
    It is recommended to remove all installed content from the module, and reset the module using 'dnf module reset <module_name>' command. 
  After you reset the module, you can install the other stream.
  stderr_lines: <omitted>
  stdout: |-
    CentOS-8 - PowerTools                           246 kB/s | 1.9 MB     00:07
    Last metadata expiration check: 0:00:04 ago on Wed 09 Sep 2020 02:33:56 PM UTC.
    Dependencies resolved.
  stdout_lines: <omitted>

any Idea ? @geerlingguy

Thanks for your help

conditional check ''php' + php_version not in item' failed - cannot concatenate 'str' and 'float' objects

Got this today with Ansible 2.5.0, not sure if it affects other Ansible versions:

TASK [geerlingguy.php-versions : Purge PHP version packages.] **********************************************************
fatal: [10.0.100.44]: FAILED! => 
  msg: |-
    The conditional check ''php' + php_version not in item' failed. The error was: Unexpected templating type error occurred on ({% if 'php' + php_version not in item %} True {% else %} False {% endif %}): cannot concatenate 'str' and 'float' objects
  
    The error appears to have been in '/Users/jeff.geerling/Dropbox/Development/GitHub/drupal-pi/roles/geerlingguy.php-versions/tasks/setup-Debian.yml': line 41, column 3, but may
    be elsewhere in the file depending on the exact syntax problem.
  
    The offending line appears to be:
  
    # PHP package purges.
    - name: Purge PHP version packages.
      ^ here

Php 8.0 install error caused by php-json

Hi,
This line is problematic when installing php 8.0 on a Debian system :

- "php{{ php_version }}-json"

php-json is packaged with php 8.0 by default, we get the error: Package 'php8.0-json' has no installation candidate

fatal: [monitoring01]: FAILED! => {
    "cache_update_time": 1607244127,
    "cache_updated": false,
    "changed": false,
    "invocation": {
        "module_args": {
            "allow_unauthenticated": false,
            "autoclean": false,
            "autoremove": false,
            "cache_valid_time": 0,
            "deb": null,
            "default_release": null,
            "dpkg_options": "force-confdef,force-confold",
            "force": false,
            "force_apt_get": false,
            "install_recommends": false,
            "name": [
                "php8.0",
                "php8.0-apcu",
                "php8.0-cli",
                "php8.0-common",
                "php8.0-curl",
                "php8.0-dev",
                "php8.0-fpm",
                "php8.0-gd",
                "php8.0-imap",
                "php8.0-json",
                "php8.0-mbstring",
                "php8.0-opcache",
                "php8.0-sqlite3",
                "php8.0-xml",
                "php8.0-yaml"
            ],
            "only_upgrade": false,
            "package": [
                "php8.0",
                "php8.0-apcu",
                "php8.0-cli",
                "php8.0-common",
                "php8.0-curl",
                "php8.0-dev",
                "php8.0-fpm",
                "php8.0-gd",
                "php8.0-imap",
                "php8.0-json",
                "php8.0-mbstring",
                "php8.0-opcache",
                "php8.0-sqlite3",
                "php8.0-xml",
                "php8.0-yaml"
            ],
            "policy_rc_d": null,
            "purge": false,
            "state": "present",
            "update_cache": null,
            "update_cache_retries": 5,
            "update_cache_retry_max_delay": 12,
            "upgrade": null
        }
    },
    "msg": "'/usr/bin/apt-get -y -o \"Dpkg::Options::=--force-confdef\" -o \"Dpkg::Options::=--force-confold\"      install 'php8.0' 'php8.0-apcu' 'php8.0-cli' 'php8.0-common' 'php8.0-curl' 'php8.0-dev' 'php8.0-fpm' 'php8.0-gd' 'php8.0-imap' 'php8.0-json' 'php8.0-mbstring' 'php8.0-opcache' 'php8.0-sqlite3' 'php8.0-xml' 'php8.0-yaml' -o APT::Install-Recommends=no' failed: E: Package 'php8.0-json' has no installation candidate\n",
    "rc": 100,
    "stderr": "E: Package 'php8.0-json' has no installation candidate\n",
    "stderr_lines": [
        "E: Package 'php8.0-json' has no installation candidate"
    ],
    "stdout": "Reading package lists...\nBuilding dependency tree...\nReading state information...\nPackage php8.0-json is a virtual package provided by:\n  php8.0-phpdbg 8.0.0-1+0~20201206.6+debian9~1.gbp33744b\n  php8.0-fpm 8.0.0-1+0~20201206.6+debian9~1.gbp33744b\n  php8.0-cli 8.0.0-1+0~20201206.6+debian9~1.gbp33744b\n  php8.0-cgi 8.0.0-1+0~20201206.6+debian9~1.gbp33744b\n  libphp8.0-embed 8.0.0-1+0~20201206.6+debian9~1.gbp33744b\n  libapache2-mod-php8.0 8.0.0-1+0~20201206.6+debian9~1.gbp33744b\n\n",
    "stdout_lines": [
        "Reading package lists...",
        "Building dependency tree...",
        "Reading state information...",
        "Package php8.0-json is a virtual package provided by:",
        "  php8.0-phpdbg 8.0.0-1+0~20201206.6+debian9~1.gbp33744b",
        "  php8.0-fpm 8.0.0-1+0~20201206.6+debian9~1.gbp33744b",
        "  php8.0-cli 8.0.0-1+0~20201206.6+debian9~1.gbp33744b",
        "  php8.0-cgi 8.0.0-1+0~20201206.6+debian9~1.gbp33744b",
        "  libphp8.0-embed 8.0.0-1+0~20201206.6+debian9~1.gbp33744b",
        "  libapache2-mod-php8.0 8.0.0-1+0~20201206.6+debian9~1.gbp33744b",
        ""
    ]
}

The `php_install_recommends` value is created and not honoured.

The variable created at

- name: Define php_install_recommends variable.
set_fact:
php_install_recommends: "{{ php_versions_install_recommends }}"
is created and then never used in any task.

It seems the intent is to allow controlling the --no-install-recommends flag of apt in debian when looking at the variable default:

# For Debian OSes only.

without this, we are seeing apache2 be installed on servers we intend to use with nginx / fpm:

ubuntu@uat-shg-esb:/var/log/apt$ aptitude why apache2
i   php8.1                Depends    libapache2-mod-php8.1 | php8.1-fpm | php8.1-cgi
p   libapache2-mod-php8.1 Recommends apache2

Is this a mistake or are we missing something?

thanks for all your roles, Jeff, amazing work.

Error with PHP5 on Ubuntu 18.04 (php5-compat n/a)

Hi,
I tried to install PHP 5.6 on my Ubuntu 18.04 and it failed because php5-compat is not supporting it.
Maybe it could be just copied by the owner for 18.04 or a check for ubuntu version < 18.04 should be added.

TASK [geerlingguy.php-versions : Add repository for PHP 5 compatibility packages (Ubuntu).] **************************************************************************************************************** An exception occurred during task execution. To see the full traceback, use -vvv. The error was: apt.cache.FetchFailedException: E:The repository 'http://ppa.launchpad.net/ondrej/php5-compat/ubuntu bionic Release' does not have a Release file. fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n File \"/tmp/ansible_WQze8a/ansible_module_apt_repository.py\", line 551, in <module>\n main()\n File \"/tmp/ansible_WQze8a/ansible_module_apt_repository.py\", line 543, in main\n cache.update()\n File \"/usr/lib/python2.7/dist-packages/apt/cache.py\", line 505, in update\n raise FetchFailedException(e)\napt.cache.FetchFailedException: E:The repository 'http://ppa.launchpad.net/ondrej/php5-compat/ubuntu bionic Release' does not have a Release file.\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 1} to retry, use: --limit @/home/username/install/playbook.retry

please add dnf module reset -y php

Please add

dnf module reset -y  php

Error:

The operation would result in switching of module 'php' stream '7.2' to stream 'remi-8.0'
Error: It is not possible to switch enabled streams of a module unless explicitly enabled via configuration option module_stream_switch.
It is recommended to rather remove all installed content from the module, and reset the module using 'dnf module reset <module_name>' command. After you reset the module, you can install the other stream.
- name: Enable DNF module for CentOS 8+.
    shell: |
      dnf config-manager --set-enabled powertools
      dnf module reset -y php
      dnf module enable -y php:remi-{{ php_version }}
    args:
      warn: false
    register: dnf_module_enable
    changed_when: "'Nothing to do' not in dnf_module_enable.stdout"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.