Обновить playbooks/inventory.yml
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user