From 4a6c0f3d4c80d5615457eb031290cdf6cd98214b Mon Sep 17 00:00:00 2001 From: ogrechko Date: Wed, 10 Dec 2025 09:50:05 +0000 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20playbooks/inventory.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- playbooks/inventory.yml | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/playbooks/inventory.yml b/playbooks/inventory.yml index ef07393..3c216a1 100644 --- a/playbooks/inventory.yml +++ b/playbooks/inventory.yml @@ -144,28 +144,31 @@ Accept: "application/json" body_format: json body: - name: "{{ inventory_name }}" + # Добавляем рандом, чтобы имя было уникальным при каждом запуске + name: "{{ inventory_name }} {{ 10000 | random }}" project_id: "{{ semaphore_project_id | int }}" type: "static" ssh_key_id: "{{ semaphore_key_id | int }}" become_key_id: null + # !!! ВОТ ЭТО ПОЛЕ ОБЯЗАТЕЛЬНО !!! + repository_id: null inventory: "{{ inventory_content }}" status_code: [201, 200] register: api_response - - - name: DEBUG - Попробовать через CURL (чтобы увидеть текст ошибки) - command: > - curl -v -X POST "{{ semaphore_url }}/api/project/{{ semaphore_project_id }}/inventory" - -H "Authorization: Bearer {{ semaphore_api_token }}" - -H "Content-Type: application/json" - -d '{"name": "{{ inventory_name }}", "project_id": {{ semaphore_project_id }}, "type": "static", "ssh_key_id": {{ semaphore_key_id }}, "become_key_id": null, "inventory": "localhost ansible_connection=local"}' - register: curl_output - ignore_errors: yes + ignore_errors: yes # Чтобы увидеть вывод ошибки, если она случится - - name: Вывод ошибки CURL + # Эта задача покажет, ПОЧЕМУ именно сервер ругается (текст ошибки) + - name: ОТЛАДКА - Ответ сервера (если ошибка) debug: - var: curl_output.stderr_lines + msg: "Server response: {{ api_response.json | default(api_response.content) }}" + when: api_response.failed is defined and api_response.failed + + - name: Остановка сценария при ошибке + fail: + msg: "Не удалось создать инвентарь. См. причину выше." + when: api_response.failed is defined and api_response.failed - name: Успех debug: - msg: "Инвентарь создан! ID: {{ api_response.json.id | default('OK') }}" + msg: "Инвентарь создан! ID: {{ api_response.json.id }}" + when: api_response.status == 201 or api_response.status == 200