From 030257a09342f3600903cd41690d45642110f4b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Mei=C3=9Fner?= Date: Sun, 15 Jun 2025 19:44:13 +0200 Subject: [PATCH 1/4] Update test environment setup --- Makefile | 1 - tests/docker/setup_database.sh | 56 +++++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index db44a29..affa1db 100644 --- a/Makefile +++ b/Makefile @@ -93,7 +93,6 @@ install-deps: setup-phpipam: test-setup docker-compose -f tests/docker/docker-compose.yml up -d - sleep 30 sh tests/docker/setup_database.sh FORCE: diff --git a/tests/docker/setup_database.sh b/tests/docker/setup_database.sh index ffb2d03..82d684f 100644 --- a/tests/docker/setup_database.sh +++ b/tests/docker/setup_database.sh @@ -1,25 +1,51 @@ #!/bin/bash -if grep -iq podman <<< $(docker version 2> /dev/null) ; then - echo "Podman is installed" +exec 10>&1 +exec > /dev/null 2>&1 + +function info() { + echo "${@}" >&10 +} + +MYSQL_PING="mysqladmin ping -h ${DB_HOST:-127.0.0.1} -P ${DB_PORT:-3306} -u ${MYSQL_ROOT_USER:-root} -p${MYSQL_ROOT_PASSWORD:-rootpw}" + +if grep -qi podman <<< $(docker version 2> /dev/null) ; then + info "Podman is installed" DOCKER_CMD=$(which podman) fi -while ! nc -z "${DB_HOST:-127.0.0.1}" "${DB_PORT:-3306}"; do - echo "Waiting for database connection..." - sleep 1 -done +if "${DOCKER_CMD}" ps | grep -q phpipam_test_webserver && ! eval "${MYSQL_PING}" ; then + + info -n "Waiting for database connection " + while ! eval "${MYSQL_PING}" ; do + info -n "." + sleep 1 + done + info +fi + +info "Database is up" -echo "Database is up" +if [[ $(mysqlshow -u root -prootpw -h 127.0.0.1 -P 3306 phpipam 2>/dev/null | wc -l) -eq 5 ]] ; then -echo "Creating database ${DB_NAME:-phpipam}" -${DOCKER_CMD} exec -ti phpipam_test_webserver sh -c 'mysql -h database -u phpipam -pphpipamadmin phpipam < /phpipam/db/SCHEMA.sql' + info "Creating database ${DB_NAME:-phpipam}" + ${DOCKER_CMD} exec -t phpipam_test_webserver sh -c 'mysql -h database -u phpipam -pphpipamadmin phpipam < /phpipam/db/SCHEMA.sql' && ((init_result++)) -echo "Activating API" -mysql -u phpipam -pphpipamadmin -h "${DB_HOST:-127.0.0.1}" phpipam --execute="UPDATE settings SET api=1 WHERE id=1;" + info "Activating API" + mysql -u phpipam -pphpipamadmin -h "${DB_HOST:-127.0.0.1}" phpipam --execute="UPDATE settings SET api=1 WHERE id=1;" && ((init_result++)) -echo "Inserting API application" -mysql -u phpipam -pphpipamadmin -h "${DB_HOST:-127.0.0.1}" phpipam --execute="INSERT INTO api (app_id, app_code, app_permissions, app_security, app_lock_wait) VALUES ('ansible','aAbBcCdDeEfF00112233445566778899',2,'ssl_token',0);" + info "Inserting API application" + mysql -u phpipam -pphpipamadmin -h "${DB_HOST:-127.0.0.1}" phpipam --execute="INSERT INTO api (app_id, app_code, app_permissions, app_security, app_lock_wait) VALUES ('ansible','aAbBcCdDeEfF00112233445566778899',2,'ssl_token',0);" && ((init_result++)) + + info "Disable forced password reset" + mysql -u phpipam -pphpipamadmin -h "${DB_HOST:-127.0.0.1}" phpipam --execute="UPDATE users SET passChange = 'No' WHERE username = 'Admin';" && ((init_result++)) + + [ "$init_result" -eq 4 ] && result=successful || result=failed + +else + + info "Detabase already initiated" && exit 0 + +fi -echo "Disable forced password reset" -mysql -u phpipam -pphpipamadmin -h "${DB_HOST:-127.0.0.1}" phpipam --execute="UPDATE users SET passChange = 'No' WHERE username = 'Admin';" +info "Database initialisation $result" From f3aaaa833366fd06baeabd982370de655a4c9bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Mei=C3=9Fner?= Date: Sun, 15 Jun 2025 21:25:14 +0200 Subject: [PATCH 2/4] Update test enviroment setup For phpIPAM version 1.7.0 and above we need to set `api_stringify_results` to `true` to get stringified results from API. --- Makefile | 2 +- tests/docker/{setup_database.sh => setup_phpipam.sh} | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) rename tests/docker/{setup_database.sh => setup_phpipam.sh} (78%) diff --git a/Makefile b/Makefile index affa1db..89322ab 100644 --- a/Makefile +++ b/Makefile @@ -93,7 +93,7 @@ install-deps: setup-phpipam: test-setup docker-compose -f tests/docker/docker-compose.yml up -d - sh tests/docker/setup_database.sh + sh tests/docker/setup_phpipam.sh FORCE: diff --git a/tests/docker/setup_database.sh b/tests/docker/setup_phpipam.sh similarity index 78% rename from tests/docker/setup_database.sh rename to tests/docker/setup_phpipam.sh index 82d684f..04d534d 100644 --- a/tests/docker/setup_database.sh +++ b/tests/docker/setup_phpipam.sh @@ -3,6 +3,9 @@ exec 10>&1 exec > /dev/null 2>&1 +# split version number into semvar parts +read -r MAJOR MINOR PATCH <<<$(echo ${PHPIPAM_VERSION#v} | tr . " ") + function info() { echo "${@}" >&10 } @@ -16,6 +19,11 @@ fi if "${DOCKER_CMD}" ps | grep -q phpipam_test_webserver && ! eval "${MYSQL_PING}" ; then + if [[ ${MINOR} -ge 7 ]] ; then + info "Running version 1.7.0 or above, patching config" + ${DOCKER_CMD} exec -t phpipam_test_webserver sh -c 'sed -i "s/api_stringify_results = false/api_stringify_results = true/g" /phpipam/config.dist.php' + fi + info -n "Waiting for database connection " while ! eval "${MYSQL_PING}" ; do info -n "." @@ -44,8 +52,8 @@ if [[ $(mysqlshow -u root -prootpw -h 127.0.0.1 -P 3306 phpipam 2>/dev/null | wc else - info "Detabase already initiated" && exit 0 + info "Database already initiated" && exit 0 fi -info "Database initialisation $result" +info "Database initialization $result" From ec09f1c37a481f2ce6221af8632d978ab412bb41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Mei=C3=9Fner?= Date: Sun, 15 Jun 2025 21:51:40 +0200 Subject: [PATCH 3/4] Updated readme with workaround for phpIPAM v1.7 and above --- README.md | 28 ++++++++++++++++++++++++++++ tests/docker/docker-compose.yml | 1 - tests/docker/setup_phpipam.sh | 5 +---- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 46b19c4..3e6ceba 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,34 @@ The following dependencies have to be fulfiled by the Ansible controller. * ipaddress * phpypam>=1.0.0 +## Compatibility notice + +To ensure `phpipam-ansible-modules` work correctly with phpIPAM versions 1.7 and above, you need to modify the phpIPAM configuration to stringify API results. This is crucial because newer phpIPAM versions might return numerical values directly, which the Ansible modules might expect as strings. + +Here's how to implement the workaround: + +**1. Modify phpIPAM Configuration** + +You need to set the `api_stringify_results` variable to `true` in your phpIPAM configuration. This change should be made in the `config.php` file, which is typically located in the phpIPAM installation directory (e.g., `/var/www/html/phpipam/config.php` or `/var/www/phpipam/config.php`). + +Add or modify the following line in your `config.php` file: + +``` + +``` ## Need help? If you’ve found any issues in this release please head over to github and open a bug so we can take a look. diff --git a/tests/docker/docker-compose.yml b/tests/docker/docker-compose.yml index 2596560..251f7a7 100644 --- a/tests/docker/docker-compose.yml +++ b/tests/docker/docker-compose.yml @@ -1,4 +1,3 @@ -version: '3' services: phpipam: image: "phpipam/phpipam-www:${PHPIPAM_VERSION:-v1.4.4}" diff --git a/tests/docker/setup_phpipam.sh b/tests/docker/setup_phpipam.sh index 04d534d..05d49f2 100644 --- a/tests/docker/setup_phpipam.sh +++ b/tests/docker/setup_phpipam.sh @@ -3,9 +3,6 @@ exec 10>&1 exec > /dev/null 2>&1 -# split version number into semvar parts -read -r MAJOR MINOR PATCH <<<$(echo ${PHPIPAM_VERSION#v} | tr . " ") - function info() { echo "${@}" >&10 } @@ -19,7 +16,7 @@ fi if "${DOCKER_CMD}" ps | grep -q phpipam_test_webserver && ! eval "${MYSQL_PING}" ; then - if [[ ${MINOR} -ge 7 ]] ; then + if [[ $(echo ${PHPIPAM_VERSION:-v1.4.4} | sed -E 's/v[0-9]?.([0-9]?).[0-9]?/\1/g') -ge 7 ]] ; then info "Running version 1.7.0 or above, patching config" ${DOCKER_CMD} exec -t phpipam_test_webserver sh -c 'sed -i "s/api_stringify_results = false/api_stringify_results = true/g" /phpipam/config.dist.php' fi From 18066095a58e15231d4e4f0c55343617fe400cb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Mei=C3=9Fner?= Date: Mon, 16 Jun 2025 01:12:23 +0200 Subject: [PATCH 4/4] fix codacy findings --- tests/docker/setup_phpipam.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/docker/setup_phpipam.sh b/tests/docker/setup_phpipam.sh index 05d49f2..d28896d 100644 --- a/tests/docker/setup_phpipam.sh +++ b/tests/docker/setup_phpipam.sh @@ -16,7 +16,7 @@ fi if "${DOCKER_CMD}" ps | grep -q phpipam_test_webserver && ! eval "${MYSQL_PING}" ; then - if [[ $(echo ${PHPIPAM_VERSION:-v1.4.4} | sed -E 's/v[0-9]?.([0-9]?).[0-9]?/\1/g') -ge 7 ]] ; then + if [[ $(echo "${PHPIPAM_VERSION:-v1.4.4}" | sed -E 's/v[0-9]?.([0-9]?).[0-9]?/\1/g') -ge 7 ]] ; then info "Running version 1.7.0 or above, patching config" ${DOCKER_CMD} exec -t phpipam_test_webserver sh -c 'sed -i "s/api_stringify_results = false/api_stringify_results = true/g" /phpipam/config.dist.php' fi