From 88ab3ea123cb6f77601555e786882e7e4a106875 Mon Sep 17 00:00:00 2001 From: Paulo Ruiz Date: Fri, 17 Oct 2025 19:04:59 -0300 Subject: [PATCH] change default variables to connect via api --- docs/ZABBIX_CRUD_ROLE.md | 6 ++++-- roles/zabbix_crud/defaults/main.yml | 4 ++-- roles/zabbix_crud/tasks/main.yml | 8 ++++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/docs/ZABBIX_CRUD_ROLE.md b/docs/ZABBIX_CRUD_ROLE.md index 13c1972cd..f249acc0d 100644 --- a/docs/ZABBIX_CRUD_ROLE.md +++ b/docs/ZABBIX_CRUD_ROLE.md @@ -31,8 +31,10 @@ See `defaults/main.yml` for more details. `zabbix_api_use_ssl`: use SSL for httpapi connection, `false` by default. `zabbix_api_validate_certs`: validate certs for httpapi connection, `false` by default. `zabbix_api_zabbix_url_path`: path to web directory or alias, `zabbix` by default. -`zabbix_api_http_user`: login user, `Admin` by default. -`zabbix_api_http_password`: login password, `zabbix` by default. +`zabbix_api_login_user`: Username of user which has API access. +`zabbix_api_login_pass`: Password for the user which has API access. +`zabbix_api_http_user`: The http user to access zabbix url with Basic Auth (if your Zabbix is behind a proxy with HTTP Basic Auth). +`zabbix_api_http_password`: The http password to access zabbix url with Basic Auth (if your Zabbix is behind a proxy with HTTP Basic Auth). `zabbix_api_auth_key`: API token for access. Not set by default. # Example Playbook diff --git a/roles/zabbix_crud/defaults/main.yml b/roles/zabbix_crud/defaults/main.yml index c24cc694b..c8e40398a 100644 --- a/roles/zabbix_crud/defaults/main.yml +++ b/roles/zabbix_crud/defaults/main.yml @@ -6,8 +6,8 @@ zabbix_api_server_port: 80 zabbix_api_url_path: 'zabbix' zabbix_api_use_ssl: false zabbix_api_validate_certs: false -zabbix_api_http_user: Admin -zabbix_api_http_password: !unsafe zabbix +zabbix_api_login_user: Admin +zabbix_api_login_pass: !unsafe zabbix # zabbix_api_auth_key: a_previously_generated_token diff --git a/roles/zabbix_crud/tasks/main.yml b/roles/zabbix_crud/tasks/main.yml index d4d2d0b32..f7619ce84 100644 --- a/roles/zabbix_crud/tasks/main.yml +++ b/roles/zabbix_crud/tasks/main.yml @@ -29,8 +29,12 @@ - name: '[Zabbix CRUD] Set password access' ansible.builtin.set_fact: - ansible_user: "{{ zabbix_api_http_user }}" - ansible_httpapi_pass: "{{ zabbix_api_http_password }}" + # --- Basic Auth (Begin) --- + http_login_user: "{{ zabbix_api_http_user | default(-42) }}" + http_login_password: "{{ zabbix_api_http_password | default(-42) }}" + # --- Basic Auth (End) --- + ansible_user: "{{ zabbix_api_login_user }}" + ansible_httpapi_pass: "{{ zabbix_api_login_pass }}" when: not token_access - name: '[Zabbix CRUD] Set token access'