Automation 在什么情况下可以解释错误行为
我有一个任务,它检查所有的kibana空间,如果一些kibana空间不存在,它就会创建它 这是我的密码Automation 在什么情况下可以解释错误行为,automation,ansible,devops,Automation,Ansible,Devops,我有一个任务,它检查所有的kibana空间,如果一些kibana空间不存在,它就会创建它 这是我的密码 - name: get all kibana spaces uri: url: '{{ kibana_url }}/api/spaces/space' method: GET force_basic_auth: yes url_username: elastic url_password: "{{elastic_ca_pass }}&quo
- name: get all kibana spaces
uri:
url: '{{ kibana_url }}/api/spaces/space'
method: GET
force_basic_auth: yes
url_username: elastic
url_password: "{{elastic_ca_pass }}"
register: spaces_result
这是spaces.result变量(所有存在的kibana空间)的输出
所以我们有一个2个Kibana空间(塔吉克斯坦和乌兹别克斯坦)
接下来的任务是创建乌兹别克斯坦空间
- name: create uzbekistan kibana space
uri:
url: '{{ kibana_url }}/api/spaces/space'
method: POST
body:
{"id":"uzbekistan","name":"uzbekistan","description":"uzbekistan kibana space","color":"#aabbcc","initials":"MK","disabledFeatures":["timelion","canvas","maps","Metrics","logs","apm", "Security","uptime","advancedSettings", "machineLearning", "ingestManager"]}
body_format: json
force_basic_auth: yes
headers:
kbn-xsrf: 'true'
Content-Type: 'application/json'
url_username: elastic
url_password: " {{ elastic_ca_pass }}"
when:
- '"uzbekistan" not in spaces_result.json'
所以这个任务只有在不在空格中时才会执行,但它执行的原因是什么
ASK [../roles/elasticsearch_nopci_efk_users : create uzbekistan kibana space] ***********************************************************
fatal: [loges-prod-01-uv01]: FAILED! => {"cache_control": "private, no-cache, no-store, must-revalidate", "changed": false, "connection": "close", "content": "{\"statusCode\":409,\"error\":\"Conflict\",\"message\":\"A space with the identifier uzbekistan already exists.\"}", "content_length": "99", "content_type": "application/json; charset=utf-8", "date": "Thu, 08 Apr 2021 09:13:51 GMT", "elapsed": 0, "json": {"error": "Conflict", "message": "A space with the identifier ibank already exists.", "statusCode": 409},
那么为什么是execute呢?因为
乌兹别克斯坦
不在空格中\u result.json
。你必须在字典的name
或id
属性中放低。这可能是一个解决方案:如果没有有效和完整的json数据结构,很难100%确定(您的摘录不能按原样使用…),但基本上是为了粗略的想法=>当:“‘乌兹别克斯坦’不在(spaces_result.json | map(attribute=“name”)| list)
@Zeitounator对不起,所以地图(attribute=“name”使用grep name=乌兹别克斯坦或塔吉克斯坦,对吗?括号中的表达式在space\u结果中创建一个包含所有name
属性值的列表。json
dict列表(从您的部分摘录推断,编辑您的问题并确保完整输出…)。然后测试检查“乌兹别克斯坦”不是该名单的成员。
ASK [../roles/elasticsearch_nopci_efk_users : create uzbekistan kibana space] ***********************************************************
fatal: [loges-prod-01-uv01]: FAILED! => {"cache_control": "private, no-cache, no-store, must-revalidate", "changed": false, "connection": "close", "content": "{\"statusCode\":409,\"error\":\"Conflict\",\"message\":\"A space with the identifier uzbekistan already exists.\"}", "content_length": "99", "content_type": "application/json; charset=utf-8", "date": "Thu, 08 Apr 2021 09:13:51 GMT", "elapsed": 0, "json": {"error": "Conflict", "message": "A space with the identifier ibank already exists.", "statusCode": 409},