diff --git a/README.md b/README.md index b33a8ba..af2b7f9 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Role Variables - `phalcon_legacy`: (boolean) Uses Phalcon 2. Set false (default) to use latest version. - `phalcon_version`: (optional) Specify phalcon version. If //null// (default), it installs latest version on repository. -- `phalcon_package` : (string) Package name. +- `phalcon_package` : (string) Package name. If you don't set this variable, this role parses you PHP cli to find the best package (be careful if you want PHP5 and your main php command links to PHP7). About PHP7 ---------- diff --git a/defaults/main.yml b/defaults/main.yml index 3f17afb..af73e4e 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,3 +1,3 @@ phalcon_legacy: false phalcon_version: null -phalcon_package: 'php5-phalcon' +phalcon_package: null diff --git a/tasks/install.yml b/tasks/install.yml index 86eb3f0..3aae1ae 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -15,3 +15,24 @@ apt_repository: > repo="{{ phalcon_apt }}" state="{{ 'absent' if phalcon_legacy else 'present' }}" + +- name: Get PHP + shell: php --version | grep -o '^PHP [[:digit:]]\.[[:digit:]]' | awk '{ print $NF }' + register: phpversion + failed_when: false + changed_when: false + +- block: + + - name: SET_FACT | Set php5-phalcon + set_fact: phalcon_package='php5-phalcon' + when: phpversion.stdout.find('5') != -1 + + - name: SET_FACT | Set package from PHP version (manages PHP 7.x) + set_fact: phalcon_package='php{{ phpversion.stdout }}-phalcon' + when: phpversion.stdout.find('5') == -1 + + when: > + phalcon_package is none and + not phpversion.failed + diff --git a/tasks/legacy.yml b/tasks/legacy.yml index 179ecc5..157b883 100644 --- a/tasks/legacy.yml +++ b/tasks/legacy.yml @@ -10,4 +10,3 @@ apt_repository: > repo="{{ phalcon_legacy_apt }}" state="{{ 'present' if phalcon_legacy else 'absent' }}" - diff --git a/tests/group_vars/php5 b/tests/group_vars/php5 index 67b7235..d6470b3 100644 --- a/tests/group_vars/php5 +++ b/tests/group_vars/php5 @@ -1,3 +1,2 @@ -phalcon_package: 'php5-phalcon' test_packages: - php5-cli diff --git a/tests/group_vars/php7 b/tests/group_vars/php7 index c024b8d..3e66dc2 100644 --- a/tests/group_vars/php7 +++ b/tests/group_vars/php7 @@ -1,3 +1,2 @@ -phalcon_package: 'php7.0-phalcon' test_packages: - php7.0-cli