semaphore icon indicating copy to clipboard operation
semaphore copied to clipboard

Problem: Unable to Update an Ansible Project Template when there are existing Vaults

Open nima-1278 opened this issue 3 months ago • 2 comments

Issue

When trying to Update an existing Ansible Project Template:

HTTP PUT http://{{host}}:{{port}}/api/project/{{Project-id}}/templates/{{Template-id}}/

{
   ....
    "vaults": [
        {
            "name": "TEST",
            "type": "password",
            "vault_key_id": 7
        }
    ]
}

If the template already has a vault with the same template_id, vault_key_id, name which are basically the unique constraint in the table project__template_vault

400 Bad Request http error is generated.

Impact

Web-Backend (APIs)

Installation method

Package

Database

Postgres

Browser

Chrome

Semaphore Version

2.16.37

Ansible Version

2.16.4

Logs & errors

time="2025-11-06T19:52:49Z" level=error msg="pq: duplicate key value violates unique constraint \"project__template_vault_template_id_vault_key_id_name_key\""

Manual installation - system information

Photon 5

Configuration

NA

Additional information

Trying to Update an existing Ansible Project Template with the same vault should not raise an error.

nima-1278 avatar Nov 06 '25 19:11 nima-1278

@nima-1278 can't reproduce for Semaphore 2.16.43 / Postgres 17

fiftin avatar Nov 07 '25 17:11 fiftin

I just upgraded to 2.16.43 and same error occurred:


Nov 10 13:49:51 c4l-otg-ansible.core.u.c4isrtdc.lab semaphore[571626]: time="2025-11-10T13:49:51Z" level=error msg="pq: duplicate key value violates unique constraint \"project__template_vault_template_id_vault_key_id_name_key\""
Nov 10 13:49:51 c4l-otg-ansible.core.u.c4isrtdc.lab semaphore[571626]: goroutine 704 [running]:
Nov 10 13:49:51 c4l-otg-ansible.core.u.c4isrtdc.lab semaphore[571626]: runtime/debug.Stack()
Nov 10 13:49:51 c4l-otg-ansible.core.u.c4isrtdc.lab semaphore[571626]:         /opt/hostedtoolcache/go/1.25.3/x64/src/runtime/debug/stack.go:26 +0x5e
Nov 10 13:49:51 c4l-otg-ansible.core.u.c4isrtdc.lab semaphore[571626]: runtime/debug.PrintStack()
Nov 10 13:49:51 c4l-otg-ansible.core.u.c4isrtdc.lab semaphore[571626]:         /opt/hostedtoolcache/go/1.25.3/x64/src/runtime/debug/stack.go:18 +0x13
Nov 10 13:49:51 c4l-otg-ansible.core.u.c4isrtdc.lab semaphore[571626]: github.com/semaphoreui/semaphore/api/helpers.WriteError({0x295e230, 0xc000168960}, {0x295a280, 0xc000212480})
Nov 10 13:49:51 c4l-otg-ansible.core.u.c4isrtdc.lab semaphore[571626]:         /home/runner/work/semaphore/semaphore/api/helpers/write_response.go:52 +0x192
Nov 10 13:49:51 c4l-otg-ansible.core.u.c4isrtdc.lab semaphore[571626]: github.com/semaphoreui/semaphore/api/projects.UpdateTemplate({0x295e230, 0xc000168960}, 0xc00039b040)

Please note that this only happens IF there is a vault name provided in the update template http PUT request. First run will create the vault associated to the template, second run it will face the error:

 "vaults": [
        {
            "name": "TEST",
            "type": "password",
            "vault_key_id": 13
        }
    ]

nima-1278 avatar Nov 10 '25 13:11 nima-1278