diff --git a/defaults/main.yml b/defaults/main.yml index 70affadfc1e6492f8d5b171c68a49e3c10a48907..067d88cf3c2a0e1c5b6c55555ccb91cec988297d 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -15,7 +15,7 @@ php_versions: phpdbg: state: absent '8.0': - state: present + state: absent sapis: apache2: state: absent diff --git a/tasks/absent.yml b/tasks/absent.yml index 125a8e2b79550ad93ac23afe596e238955a5d1dd..ece2cc5af51f1e1c967960d55943ac9566a6572e 100644 --- a/tasks/absent.yml +++ b/tasks/absent.yml @@ -2,26 +2,18 @@ - name: PHP packages absent block: - - name: PHP packages absent + - name: "PHP {{ version }} packages absent" apt: pkg: "php{{ version }}*" state: absent purge: true autoclean: true autoremove: true - loop: "{{ php_versions_remove }}" - loop_control: - loop_var: version - label: "{{ version }}" - - name: PHP config files absent + - name: "PHP {{ version }} config files absent" file: path: "/etc/php/{{ version }}/" state: absent - loop: "{{ php_versions_remove }}" - loop_control: - loop_var: version - label: "{{ version }}" tags: - php diff --git a/tasks/checks.yml b/tasks/checks.yml index e26ba2acfa4464dfe0b5bdb2d404d01f56e3413e..bea03fd794b7c269a733a926e4065fa12a88adc1 100644 --- a/tasks/checks.yml +++ b/tasks/checks.yml @@ -2,9 +2,6 @@ - name: PHP checks block: - # TODO - # - Check that when a version SAPI is set to present the version is also set to present - # - Check that when a version is set to absent the SAPIs are also set to absent, if the state is set - name: Check that depreciated variables are not used assert: that: @@ -64,6 +61,14 @@ var: php_versions_remove verbosity: 2 + - name: Include SAPI checks for PHP proposed versions + include_tasks: sapi_checks.yml + loop: "{{ php_versions_remove }}" + loop_control: + loop_var: version + label: "{{ version }}" + when: ( php_versions_remove is defined ) and ( php_versions_remove != [] ) + # - name: Include SAPI checks for PHP proposed versions # include_tasks: sapi_checks.yml # loop: "{{ php_proposed_versions }}" diff --git a/tasks/main.yml b/tasks/main.yml index b9626a2e00409d73fc5a988cc5745f762425906a..b250646c85fae220c1a567a1d1b5adb31646bee3 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -13,8 +13,20 @@ - name: Include package removal tasks include_tasks: absent.yml + loop: "{{ php_versions_remove }}" + loop_control: + loop_var: version + label: "{{ version }}" when: ( php_versions_remove is defined ) and ( php_versions_remove != [] ) + - name: Include package install tasks + include_tasks: present.yml + loop: "{{ php_versions_install }}" + loop_control: + loop_var: version + label: "{{ version }}" + when: ( php_versions_install is defined ) and ( php_versions_install != [] ) + - name: Debug fail fail: diff --git a/tasks/sapi_checks.yml b/tasks/sapi_checks.yml index f92d15744b62f1d4cd5cd436dbcaf7c8e513e5a2..fc97e03fccb8970003e746aa3f3a1abe7538fe2d 100644 --- a/tasks/sapi_checks.yml +++ b/tasks/sapi_checks.yml @@ -7,26 +7,39 @@ var: version verbosity: 2 - - name: "Debug existing SAPIs for PHP {{ version }}" - debug: - var: ansible_local.phpquery.versions[version].sapis - verbosity: 3 - when: ansible_local.phpquery.versions[version].sapis is defined - - - name: "Set an array for the existing SAPIs for PHP {{ version }}" - set_fact: - php_existing_sapis: "{{ php_existing_sapis | default([]) }} + [ '{{ existing_sapi.key }}' ]" - when: - - ansible_local.phpquery.versions[version].sapis is defined - - existing_sapi.value.state == "present" - loop: "{{ ansible_local.phpquery.versions[version].sapis | dict2items }}" + - name: "Check that no SAPI is set to be present when PHP {{ version }} is set to be removed" + assert: + that: + - sapi.state == absent ) + loop: "{{ php_versions[version].sapis }}" loop_control: - loop_var: existing_sapi - label: "{{ existing_sapi.key }}" + loop_var: sapi + label: + when: + - php_versions[version].sapis is defined + - php_versions[version].sapis.sapi is defined + - php_versions[version].sapis.sapi.state is defined - - name: "Debug existing SAPIs for PHP {{ version }}" - debug: - var: php_existing_sapis + # - name: "Debug existing SAPIs for PHP {{ version }}" + # debug: + # var: ansible_local.phpquery.versions[version].sapis + # verbosity: 3 + # when: ansible_local.phpquery.versions[version].sapis is defined + + # - name: "Set an array for the existing SAPIs for PHP {{ version }}" + # set_fact: + # php_existing_sapis: "{{ php_existing_sapis | default([]) }} + [ '{{ existing_sapi.key }}' ]" + # when: + # - ansible_local.phpquery.versions[version].sapis is defined + # - existing_sapi.value.state == "present" + # loop: "{{ ansible_local.phpquery.versions[version].sapis | dict2items }}" + # loop_control: + # loop_var: existing_sapi + # label: "{{ existing_sapi.key }}" + + # - name: "Debug existing SAPIs for PHP {{ version }}" + # debug: + # var: php_existing_sapis # - name: Generate an array of proposed PHP SAPIs # set_fact: