From f4042b27c0b982c9925021566c85e534339f6551 Mon Sep 17 00:00:00 2001 From: Lino Schmidt Date: Wed, 21 Oct 2026 18:36:31 +0200 Subject: [PATCH 1/3] Added phpcheck playbook --- README.md | 12 ++++++++ playbooks/phpcheck.yml | 68 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 playbooks/phpcheck.yml diff --git a/README.md b/README.md index 13eb736..9757073 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,18 @@ run a playbook with sudo: ansible-playbook playbooks/.yml -K ``` +check PHP versions on hosts and in running Docker containers: + +```bash +ansible-playbook playbooks/phpcheck.yml +``` + +with sudo (e.g. if the user is not in the docker group): + +```bash +ansible-playbook playbooks/phpcheck.yml -K -e phpcheck_become=true +``` + ## WSL Setup Instructions To use Ansible on Windows, you need to set up Windows Subsystem for Linux (WSL). diff --git a/playbooks/phpcheck.yml b/playbooks/phpcheck.yml new file mode 100644 index 0000000..01a1c16 --- /dev/null +++ b/playbooks/phpcheck.yml @@ -0,0 +1,68 @@ +--- +- name: Check PHP versions + hosts: all + gather_facts: false + become: "{{ phpcheck_become }}" + vars: + phpcheck_become: false + phpcheck_oldest_branch: "8.2" + phpcheck_min_versions: + "8.2": "8.2.35" + "8.3": "8.3.36" + "8.4": "8.4.27" + "8.5": "8.5.12" + tasks: + - name: Get host PHP version + ansible.builtin.shell: command -v php >/dev/null 2>&1 && php -r 'echo PHP_VERSION;' + register: phpcheck_host + changed_when: false + failed_when: false + + - name: Check if docker is installed + ansible.builtin.command: + argv: [sh, -c, command -v docker] + register: phpcheck_docker + changed_when: false + failed_when: false + + - name: List running containers + ansible.builtin.command: docker ps --format '{% raw %}{{.Names}}{% endraw %}' + register: phpcheck_containers + changed_when: false + failed_when: false + when: phpcheck_docker.rc == 0 + + - name: Get container PHP versions + ansible.builtin.command: + argv: [docker, exec, "{{ item }}", php, -r, "echo PHP_VERSION;"] + loop: "{{ phpcheck_containers.stdout_lines | default([]) }}" + register: phpcheck_container_php + changed_when: false + failed_when: false + when: phpcheck_containers.rc | default(1) == 0 + + - name: Evaluate PHP versions + ansible.builtin.set_fact: + phpcheck_report: "{{ phpcheck_report | default([]) + [item.0 ~ ': ' ~ phpcheck_status] }}" + loop: >- + {{ [['host', phpcheck_host.stdout | default('')]] + + (phpcheck_container_php.results | default([]) | map(attribute='item') | map('regex_replace', '^', 'container ') + | zip(phpcheck_container_php.results | default([]) | map(attribute='stdout', default='')) | list) }} + vars: + phpcheck_version: "{{ item.1 | regex_search('^[0-9]+\\.[0-9]+\\.[0-9]+') | default('', true) }}" + phpcheck_branch: "{{ phpcheck_version.split('.')[:2] | join('.') }}" + phpcheck_status: >- + {{ 'none' if not phpcheck_version + else phpcheck_version ~ ' VULNERABLE (EOL)' if phpcheck_branch is version(phpcheck_oldest_branch, '<') + else phpcheck_version ~ ' UNKNOWN (no minimum defined)' if phpcheck_branch not in phpcheck_min_versions + else phpcheck_version ~ ' VULNERABLE (< ' ~ phpcheck_min_versions[phpcheck_branch] ~ ')' + if phpcheck_version is version(phpcheck_min_versions[phpcheck_branch], '<') + else phpcheck_version ~ ' OK' }} + + - name: Print PHP versions + ansible.builtin.debug: + msg: >- + {{ phpcheck_report + + (['docker: not installed'] if phpcheck_docker.rc != 0 else []) + + (['docker: not accessible (' ~ phpcheck_containers.stderr | default('') | trim ~ ')'] + if phpcheck_docker.rc == 0 and phpcheck_containers.rc | default(0) != 0 else []) }} -- 2.54.0 From d3a70eca24db49ce1ab06fcd90982f730944bf0d Mon Sep 17 00:00:00 2001 From: Lino Schmidt Date: Wed, 21 Oct 2026 19:17:23 +0200 Subject: [PATCH 2/3] phpcheck: fall back to sudo for docker automatically --- README.md | 8 +------- playbooks/phpcheck.yml | 41 ++++++++++++++++++++++++++++++++--------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 9757073..4da8edb 100644 --- a/README.md +++ b/README.md @@ -20,18 +20,12 @@ run a playbook with sudo: ansible-playbook playbooks/.yml -K ``` -check PHP versions on hosts and in running Docker containers: +check PHP versions on hosts and in running Docker containers (falls back to sudo for Docker if needed, add `-K` if sudo requires a password): ```bash ansible-playbook playbooks/phpcheck.yml ``` -with sudo (e.g. if the user is not in the docker group): - -```bash -ansible-playbook playbooks/phpcheck.yml -K -e phpcheck_become=true -``` - ## WSL Setup Instructions To use Ansible on Windows, you need to set up Windows Subsystem for Linux (WSL). diff --git a/playbooks/phpcheck.yml b/playbooks/phpcheck.yml index 01a1c16..88ae41a 100644 --- a/playbooks/phpcheck.yml +++ b/playbooks/phpcheck.yml @@ -2,9 +2,8 @@ - name: Check PHP versions hosts: all gather_facts: false - become: "{{ phpcheck_become }}" + become: false vars: - phpcheck_become: false phpcheck_oldest_branch: "8.2" phpcheck_min_versions: "8.2": "8.2.35" @@ -32,14 +31,30 @@ failed_when: false when: phpcheck_docker.rc == 0 + - name: List running containers with sudo + ansible.builtin.command: docker ps --format '{% raw %}{{.Names}}{% endraw %}' + become: true + register: phpcheck_containers_sudo + changed_when: false + ignore_errors: true + when: + - phpcheck_docker.rc == 0 + - phpcheck_containers.rc != 0 + - phpcheck_containers.stderr is search('permission denied|docker\.sock|docker daemon', ignorecase=true) + + - name: Select container list + ansible.builtin.set_fact: + phpcheck_use_become: "{{ phpcheck_containers_sudo is not skipped }}" + phpcheck_list: "{{ phpcheck_containers_sudo if phpcheck_containers_sudo is not skipped else phpcheck_containers }}" + - name: Get container PHP versions ansible.builtin.command: argv: [docker, exec, "{{ item }}", php, -r, "echo PHP_VERSION;"] - loop: "{{ phpcheck_containers.stdout_lines | default([]) }}" + become: "{{ phpcheck_use_become }}" + loop: "{{ phpcheck_list.stdout_lines | default([]) if phpcheck_list.rc | default(1) == 0 else [] }}" register: phpcheck_container_php changed_when: false failed_when: false - when: phpcheck_containers.rc | default(1) == 0 - name: Evaluate PHP versions ansible.builtin.set_fact: @@ -61,8 +76,16 @@ - name: Print PHP versions ansible.builtin.debug: - msg: >- - {{ phpcheck_report - + (['docker: not installed'] if phpcheck_docker.rc != 0 else []) - + (['docker: not accessible (' ~ phpcheck_containers.stderr | default('') | trim ~ ')'] - if phpcheck_docker.rc == 0 and phpcheck_containers.rc | default(0) != 0 else []) }} + msg: "{{ phpcheck_report + ([phpcheck_docker_line] if phpcheck_docker_line else []) }}" + vars: + phpcheck_sudo_msg: "{{ phpcheck_list.msg | default('') if phpcheck_list is failed else '' }}" + phpcheck_need_k: "{{ phpcheck_sudo_msg is search('password is required|terminal is required|missing sudo password', ignorecase=true) }}" + phpcheck_wrong_pw: "{{ phpcheck_sudo_msg is search('incorrect|sorry, try again|duplicate become password', ignorecase=true) }}" + phpcheck_docker_line: >- + {{ 'docker: not installed' if phpcheck_docker.rc != 0 + else 'docker: no access, run with -K' if phpcheck_need_k + else 'docker: no access, wrong sudo password' if phpcheck_wrong_pw + else 'docker: error (' ~ (phpcheck_list.stderr | default('', true) or phpcheck_sudo_msg) | trim ~ ')' + if phpcheck_list.rc | default(1) != 0 + else 'docker: no running containers' if phpcheck_list.stdout_lines | default([]) | length == 0 + else '' }} -- 2.54.0 From ec0d5c6f9b6beb6d26692668774412c82f22d2d7 Mon Sep 17 00:00:00 2001 From: Lino Schmidt Date: Wed, 21 Oct 2026 19:30:58 +0200 Subject: [PATCH 3/3] Revert README changes --- README.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/README.md b/README.md index 4da8edb..13eb736 100644 --- a/README.md +++ b/README.md @@ -20,12 +20,6 @@ run a playbook with sudo: ansible-playbook playbooks/.yml -K ``` -check PHP versions on hosts and in running Docker containers (falls back to sudo for Docker if needed, add `-K` if sudo requires a password): - -```bash -ansible-playbook playbooks/phpcheck.yml -``` - ## WSL Setup Instructions To use Ansible on Windows, you need to set up Windows Subsystem for Linux (WSL). -- 2.54.0