Ansible 如何卸下双引号方括号&;单一报价?
我得到了ansible变量的以下输出,但我只想存储domain-c39Ansible 如何卸下双引号方括号&;单一报价?,ansible,Ansible,我得到了ansible变量的以下输出,但我只想存储domain-c39 output: "['domain-c39']" expected output: domain-c39 我该怎么做?有什么意见吗 这是剧本 - name: Get cluster MOD uri: url: https://192.168.200.224/rest/vcenter/cluster?filter.names=test-clr force_basic_auth: yes v
output: "['domain-c39']"
expected output: domain-c39
我该怎么做?有什么意见吗
这是剧本
- name: Get cluster MOD
uri:
url: https://192.168.200.224/rest/vcenter/cluster?filter.names=test-clr
force_basic_auth: yes
validate_certs: no
headers:
Cookie: "{{ login.set_cookie }}"
register: cluster_id
- name: store moid for required cluster
shell: echo "{{ cluster_id | json_query('json.value[*].cluster') }}"
register: cluster_moid
这是输出
TASK [debug] ***********************************************************************************************************************************************************
ok: [localhost] => {
"msg": {
"changed": true,
"cmd": "echo \"['domain-c39']\"",
"delta": "0:00:00.002944",
"end": "2020-05-13 18:22:43.316235",
"failed": false,
"rc": 0,
"start": "2020-05-13 18:22:43.313291",
"stderr": "",
"stderr_lines": [],
"stdout": "['domain-c39']",
"stdout_lines": [
"['domain-c39']"
]
}
}
没有理由在
shell
任务中使用echo
;您可以使用set\u fact
创建一个包含所需内容的新变量:
- name: store moid for required cluster
set_fact:
cluster_moid: "{{ cluster_id | json_query('json.value[*].cluster') }}"
这将创建一个新的
cluster\u moid
变量,该变量具有您想要的值。您需要向我们展示您的剧本。您首先是如何设置该值的?在设置变量之后,我添加了playbook&output,然后也输出ok:[localhost]=>{“ansible\u facts”:{“cluster\u moid”:[“domain-c39”]},changed]:false}我只想将这个值存储在variable domain-c39中,然后您需要更新您的问题,以准确显示集群id
变量的内容,因为没有这些信息,我只是猜测。