--- - name: Auth to Central with Ansible hosts: localhost connection: local gather_facts: false vars: base_url: https://app1-apigw.central.arubanetworks.com url1: /oauth2/authorize/central/api/login url2: /oauth2/authorize/central/api url3: /oauth2/token authurl: '{{ base_url }}{{ url1 }}' authcodeurl: '{{ base_url }}{{ url2 }}' swap_url: '{{ base_url }}{{ url3 }}' client_id: your client id client_secret: your client secret username: someusername@mail.com password: password for user params1: '?client_id={{ client_id }}' params2: '?client_id={{ client_id }}&response_type=code&scope=all' params3: '?client_id={{ client_id }}&client_secret={{ client_secret }}&grant_type=authorization_code' customer_id: your customer id tasks: - name: Running first API call to Central with Ansible uri: url: '{{ authurl }}{{ params1 }}' method: POST body_format: json body: username: '{{ username }}' password: '{{ password }}' headers: Content-Type: application/json register: login - name: debug to view login output debug: var=login - name: Gathering Auth Code uri: url: '{{ authcodeurl }}{{ params2 }}' method: POST body_format: json body: customer_id: '{{ customer_id }}' headers: X-CSRF-TOKEN: '{{ login.cookies.csrftoken }}' Cookie: 'session={{ login.cookies.session }}' Content-Type: application/json register: auth - name: debug to show auth code output debug: var=auth - name: Gathering access_refresh tokens uri: url: '{{ swap_url }}{{ params3 }}&code={{ auth.json.auth_code }}' method: POST register: acc_ref - name: debug to show tokens debug: var=acc_ref #These dedugs are to show specific tokens. #You could set these as a fact to use later in playbooks - name: Access Token debug: var=acc_ref.json.access_token - name: Refresh Token debug: var=acc_ref.json.refresh_token ...