# uri post to avoid duplicate

**URL:** <https://forum.ansible.com/t/uri-post-to-avoid-duplicate/38345>\
**Category:** Ansible Project\
**Created:** [August 17, 2023, 8:18am UTC](https://forum.ansible.com/t/uri-post-to-avoid-duplicate/38345 "2023-08-17T08:18:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Veera](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/veera/32/4107_2.png) [@Veera](https://forum.ansible.com/u/Veera)\
**Post date:** [August 17, 2023, 8:18am UTC](https://forum.ansible.com/t/uri-post-to-avoid-duplicate/38345/1 "2023-08-17T08:18:47Z")

</div>

Hi ,

I have the below uri module to post the details inside the web api

- name: REST POST Example  
uri:  
url: “{{ webapp\_url }}/api/orgs”  
method: POST  
return\_content: yes  
body: “{ "name": "{{ project\_name }}" }”  
body\_format: json  
validate\_certs: no  
user: “{{ user }}”  
password: “{{ password }}”  
force\_basic\_auth: yes

while passing the variables as  
ansible-playbook myplay.yml -e “project\_name=first\_project”  
n- number of times it works and overwrites the same first\_project name.

Is there an option available to stop overwriting if the same project\_name is available with uri module?  
Or we have to use the GET method to collect and compare the existing project\_name , before writing using POST? or will a conditional check can help ?

---

<div class="post-metadata">

**Author:** ![atul\_mohan](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@atul\_mohan](https://forum.ansible.com/u/atul_mohan)\
**Post date:** [August 19, 2023, 5:04pm UTC](https://forum.ansible.com/t/uri-post-to-avoid-duplicate/38345/2 "2023-08-19T17:04:15Z")

</div>

- name: Check if project name exists  
uri:  
url: “{{ webapp\_url }}/api/orgs”  
method: GET  
return\_content: yes  
validate\_certs: no  
user: “{{ user }}”  
password: “{{ password }}”  
force\_basic\_auth: yes  
register: existing\_projects

- name: Check if project name exists in the response  
set\_fact:  
project\_already\_exists: “{{ project\_name in existing\_projects.json | json\_query(‘\*.name’) }}”

- name: REST POST Example if project name doesn’t exist  
uri:  
url: “{{ webapp\_url }}/api/orgs”  
method: POST  
return\_content: yes  
body: “{ "name": "{{ project\_name }}" }”  
body\_format: json  
validate\_certs: no  
user: “{{ user }}”  
password: “{{ password }}”  
force\_basic\_auth: yes  
when: not project\_already\_exists

---

<div class="post-metadata">

**Author:** ![Veera](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/veera/32/4107_2.png) [@Veera](https://forum.ansible.com/u/Veera)\
**Post date:** [August 23, 2023, 9:10am UTC](https://forum.ansible.com/t/uri-post-to-avoid-duplicate/38345/3 "2023-08-23T09:10:40Z")

</div>

Thanks … I am able to achieve it with the above logic and with “assert” module for exiting the playbook if failed .
