title: How to use the Ansible uri module to POST a file as form-data?
body: <p>SonarQube allows the upload of a <code>profile.xml</code> file via form-data <code>POST</code> request as follows:</p>
  
  <pre><code>curl -u admin:admin -X POST http://sonar:9000/qualityprofiles/restore -F backup=@profile.xml
  </code></pre>
  
  <p>I'm trying to translate this <code>curl</code> command into Ansible, using the <code>uri</code> module. Unfortunately, I don't see any chance to map the <code>-F</code> form-data option and the parameter <code>backup</code> to Ansible. Here's my attempt:</p>
  
  <pre><code>- name: create quality profile
    uri:
      url: "{{ sonar_api_url }}/qualityprofiles/restore"
      method: POST
      body: "{{ lookup('file', 'profile.xml') }}"
      user: "{{ sonar_admin_user }}"
      password: "{{ sonar_admin_pass }}"
      force_basic_auth: "yes"
      status_code: 200
  </code></pre>
  
  <p>I've also tried something like this:</p>
  
  <pre><code>    body: "backup={{ lookup('file', 'profile.xml') }}"
  </code></pre>
  
  <p>Or just like this:</p>
  
  <pre><code>    body: "backup=profile.xml"
  </code></pre>
  
  <p>But all without success. I keep getting the error "A backup file must be provided". Any ideas how this can be achieved?</p>