# Hard Code Ansible return 302 error message

**URL:** <https://forum.ansible.com/t/hard-code-ansible-return-302-error-message/21154>\
**Category:** Ansible Project\
**Created:** [April 13, 2016, 8:59pm UTC](https://forum.ansible.com/t/hard-code-ansible-return-302-error-message/21154 "2016-04-13T20:59:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GBANE\_FETIGUE](https://avatars.discourse-cdn.com/v4/letter/g/6bbea6/32.png) [@GBANE\_FETIGUE](https://forum.ansible.com/u/GBANE_FETIGUE)\
**Post date:** [April 13, 2016, 8:59pm UTC](https://forum.ansible.com/t/hard-code-ansible-return-302-error-message/21154/1 "2016-04-13T20:59:22Z")

</div>

Hi Folks,  
I am writing that ansible to register Mule server .It’s fine you don’t Mule I do believe you can still help me. Here is the Error :

failed: [ip-172-31-57-168.ec2.internal] =\> {“content”: “”, “content\_length”: “0”, “date”: “Wed, 13 Apr 2016 20:23:32 GMT”, “failed”: true, “location”: “[http://ec2-54-165-243-43.compute-1.amazonaws.com:8080/mmc-console-3.6.2/login.jsp;jsessionid=F7534E8A910F63C9AE877723F908F55E](http://ec2-54-165-243-43.compute-1.amazonaws.com:8080/mmc-console-3.6.2/login.jsp;jsessionid=F7534E8A910F63C9AE877723F908F55E)”, “redirected”: false, “server”: “Apache-Coyote/1.1”, “set\_cookie”: “JSESSIONID=F7534E8A910F63C9AE877723F908F55E; Path=/mmc-console-3.6.2/; HttpOnly”, “status”: 302}  
msg: Status code was not [200]

FATAL: all hosts have already failed – aborting

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
to retry, use: --limit @/root/master.retry

ip-172-31-57-168.ec2.internal : ok=32 changed=8 unreachable=0 failed=1

My Ansible returning that error message is :

- uri:  
url: [http://ec2-54-165-243-43.compute-1.amazonaws.com:8080/mmc-console-3.6.2/api/servers](http://ec2-54-165-243-43.compute-1.amazonaws.com:8080/mmc-console-3.6.2/api/servers)  
method: POST  
user: admin  
password: admin  
return\_content: yes  
body: “{"name": "ec2-52-207-234-33.compute-1.amazonaws.com", "agentUrl": "http//ec2-52-207-234-33.compute-1.amazonaws.com:7777/mmc-support", "mmc\_group\_id": "local$4459223d-fa52-44b8-bdb4-7409fe96dd77"}”  
body\_format: json

In addition, whenever I am adding status\_code: 302 it run fine but that’s not what I want to do . Any ideas is Welcome !!!

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [April 13, 2016, 9:15pm UTC](https://forum.ansible.com/t/hard-code-ansible-return-302-error-message/21154/2 "2016-04-13T21:15:50Z")

</div>

What are you trying to achieve? Do you want `uri` to follow the 302?

The default for `follow_redirects` for the `uri` module is “safe”. “safe” means that it will only follow certain redirects if the request is a HEAD or GET. You are performing a POST so it does not follow the redirect.

You could add `follow_redirects: all` to get it to follow the redirect.

---

<div class="post-metadata">

**Author:** ![GBANE\_FETIGUE](https://avatars.discourse-cdn.com/v4/letter/g/6bbea6/32.png) [@GBANE\_FETIGUE](https://forum.ansible.com/u/GBANE_FETIGUE)\
**Post date:** [April 13, 2016, 11:04pm UTC](https://forum.ansible.com/t/hard-code-ansible-return-302-error-message/21154/3 "2016-04-13T23:04:02Z")

</div>

Thanks I am trying to translate the curl on ansible to register a sever . It’s possible to use a POST

curl --basic -u admin:admin -d ‘{ “name” : “Test”, “agentUrl” : “[http://localhost:7777/mmc-support](http://localhost:7777/mmc-support)”, “groupIds”:[“0bc8932b-8463-46cd-9a1f-77060756c5c0”] }’ --header ‘Content-Type: application/json’ [http://localhost:8080/mmc/api/servers](http://localhost:8080/mmc/api/servers)
