IrinaS
IrinaS

Reputation: 109

Trying to convert curl to ansible play

I am trying to convert the following curl to ansible play using uri module: curl -u user:password -X PUT "http://xxxxxxxxrest/api/1.0/projects/project/repos/my-repo/permissions/groups?permission=REPO_WRITE&name=TestGroup"

Can someone advise how to add the values in the playbook? The below does not work. ERROR: The server refused this request because the request entity is in a format not supported by the requested resource for the requested method

  - name: Add Permission to Group
    uri:
      url: http://xxxxxxxxrest/api/1.0/projects/project/repos/myrepo/permissions/groups
      method: PUT
      user: user
      password: password
      body: "permission={REPO_WRITE}"
      body: "name={TestGroup}"
      force_basic_auth: yes
      status_code: 200

Upvotes: 1

Views: 240

Answers (1)

mdaniel
mdaniel

Reputation: 33203

 body: "permission={REPO_WRITE}"
 body: "name={TestGroup}"

I don't have any idea why you moved those to the body when they're not in the body of your curl; they're query parameters in your curl, as they should be in your uri: invocation, too:

- uri:
    url: http://xx.../groups?permission=REPO_WRITE&name=TestGroup

Having said that, watch out for the non-idempotent behavior (unless you have a when: elsewhere that guards this uri:) because ansible doesn't know what the uri does and thus can't make any claims about whether that uri needs to take place or not.

Upvotes: 1

Related Questions