如何将邮递员的JWT代币纳入Ansible剧本
我试图定义一个变量来保存我从POSTMAN处为API获得的JWT令牌。以下是我的剧本定义:如何将邮递员的JWT代币纳入Ansible剧本,ansible,jwt,yaml,access-token,Ansible,Jwt,Yaml,Access Token,我试图定义一个变量来保存我从POSTMAN处为API获得的JWT令牌。以下是我的剧本定义: --- - name: Request EX API hosts: localhost connection: local tasks: - name: Get Ports uri: method: GET url: "https://api.domain.com/ex/v3/network/user
---
- name: Request EX API
hosts: localhost
connection: local
tasks:
- name: Get Ports
uri:
method: GET
url: "https://api.domain.com/ex/v3/network/userport"
return_content: yes
headers:
Accept: application/json
Authorization: "JWT {{token.json.token}}"
register: response
- debug:
msg: "{{ response.content }}"
我遇到了以下错误:
lw@APMBC02D20RHMD6R playbooks % ansible-playbook play1.yml
PLAY [Request EX API] ********************************************************************************************************************************
TASK [Gathering Facts] *********************************************************************************************************************************
[WARNING]: Platform darwin on host localhost is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information. ok: [localhost]
TASK [Get Ports] ***************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'token' is undefined\n\nThe error appears to be in '/Users/lw/Ansible-EX/playbooks/ex.yml': line 6, column 9, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: Get Ports\n ^ here\n"}
PLAY RECAP *********************************************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
lw@APMBC02D20RHMD6R playbooks %
有谁能帮我指出如何包含变量来保存来自POSTMAN的JWT令牌吗?@jps-前面的问题是关于影响缩进的问题。这里的问题是关于让变量保存来自Postman的JWT标记。你的问题有点模糊——为了制作一个包含你期望的结构的dict,你已经尝试了什么?