- hosts: '{{inventory_hostname}}'
gather_facts: no
vars:
cluser_ip: "{{ rubrik_hostname }}"
tasks:
- name: login to rubrik to generate token
uri:
url: https://{{ cluser_ip }}/api/v1/session # URL to generate an auth token to be used by subsequent calls
force_basic_auth: yes
user: '{{ lookup("env", "rubrik_username") }}'
password: '{{ lookup("env", "rubrik_password") }}'
method: POST
status_code: 200
return_content: yes
validate_certs: yes
register: authtoken # token is available as authtoken.json.token
delegate_to: localhost
become: no
- name: get target vm id
uri:
url: https://{{ cluser_ip }}/api/v1/vmware/vm?name={{ inventory_hostname_nfq }}
headers:
Content-Type: "application/json"
Authorization: "Bearer {{ authtoken.json.token }}" # pass authentication token from earlier rather than basic auth
method: GET
status_code: 200
return_content: yes
validate_certs: yes
register: vminfo
delegate_to: localhost
become: no
- name: set variable for target_vm_id
set_fact:
target_vm_id: "{{ vminfo.json.data[0].id }}"
- name: get list of snapshots
uri:
url: https://{{ cluser_ip }}/api/v1/vmware/vm/{{ source_vm_id }}/snapshot
headers:
Content-Type: "application/json"
Authorization: "Bearer {{ authtoken.json.token }}" # pass authentication token from earlier rather than basic auth
method: GET
status_code: 200
return_content: yes
register: snapshotlist
delegate_to: localhost
become: no
- name: get info on the snapshot to be used
uri:
url: https://{{ cluser_ip }}/api/v1/vmware/vm/snapshot/{{ snapshotlist.json.data[0].id }}
headers:
Content-Type: "application/json"
Authorization: "Bearer {{ authtoken.json.token }}" # pass authentication token from earlier rather than basic auth
method: GET
status_code: 200
return_content: yes
register: snapshotdetails
delegate_to: localhost
become: no