Open beye91 opened 2 years ago
For example:
- hosts: dnac_servers
vars_files:
- credentials.yml
- vars.yml
vars:
get_devices_url: "https://{{dnac_host}}:{{dnac_port}}/dna/intent/api/v1/network-device"
auth_url: "https://{{dnac_host}}:{{dnac_port}}/dna/system/api/v1/auth/token"
deviceID_lookup: "{{playbook_dir}}/DEVICE_ID_LOOKUP.yaml"
gather_facts: no
connection: local
tasks:
- name: authenticate to DNAC and get token as env variable
uri:
url: "{{auth_url}}"
method: POST
user: "{{dnac_username}}"
password: "{{dnac_password}}"
headers:
Content-Type: "application/json"
Accept: "application/json"
status_code: 200
force_basic_auth: yes
validate_certs: "{{dnac_verify}}"
register: auth_response
- debug:
var: auth_response.json.Token
- name: get list of devices
uri:
url: "{{get_devices_url}}"
method: GET
validate_certs: "{{dnac_verify}}"
headers:
x-auth-token: "{{auth_response.json.Token}}"
Content-Type: "application/json"
Accept: "application/json"
status_code: 200
register: dev_list
- debug:
var: dev_list.json.response
I would like to avoid that and it can be much more simpler.
Cheers, Chris
Thanks for the enhancement idea. We will figure out if we can include it in the next release.
I'd like to second the request or bubble it back up to the top.
As the original poster mentioned having a relatively simple workaround for any use-case that you don't currently have a module for would be very helpful.
@MTWiley We will review this when we release the next library version.
Is your feature request related to a problem? Please describe. There are always REST calls that are not implemented and it would be great to have an Ansible module like other Cisco products for example ACI: https://docs.ansible.com/ansible/latest/collections/cisco/aci/aci_rest_module.html
Describe the solution you'd like A module that only focuses on the payload and not dealing with authentication and saving the TOKEN in a separate variable.
Describe alternatives you've considered An alternative solution is the ansible.builtin.uri