Sample Header Ad - 728x90

How should I use session cookies with OVMM Rest API and Ansible URI Module

1 vote
1 answer
721 views
I am able to use the Oracle Virtual Machine Manager (OVMM) REST API successfully with the Ansible URI module with the exception that I have to pass the username and password to EACH call instead of grabbing the session cookies from the first call and using them thereafter. As I understand it the following should work, however I get a '401 Unauthorized' from the second call. I have tried a number of variations in the second call. When I debug the playbook I see the cookies (JSESSIONID and _WL_AUTHCOOKIE_JSESSIONID) are being passed as expected. To be clear, if I change the second API call to use basic_auth, username and password it works.
- name: Get OVM Manager
    local_action:
        module: uri
        url: "{{ baseuri }}/Manager"
        url_username: "{{ ovmUser }}"
        url_password: "{{ ovmPassword }}"
        validate_certs: false
        force_basic_auth: true
        method: GET
    register: login

  - name: Get info about VMs
    local_action:
      module: uri
      url: "{{ baseuri }}/Vm/id"
      validate_certs: false
      method: GET
      headers:
        Cookie: "{{ login.cookies_string }}"  # Why doesn't this work???
Asked by Justin Lake (321 rep)
Jun 17, 2022, 07:34 AM
Last activity: Aug 8, 2022, 02:54 PM