Team,
Моя цель - увидеть, присутствует ли код состояния 403 в переменной регистра, а затем выполнить IF и ELSE.Но мой «Проверить код статуса http» не оценивается ..
- name: "Validate KubeAPI Authentication response as DNS resolve worked"
uri:
url: 'https://{{ kubeapi_server }}'
return_content: yes
validate_certs: no
register: uri_output
- name: "Validate http status code"
debug:
msg: "Received 403"
when: uri_output.status == 403
Полученный вывод:
PLAY [Test connectivity to target servers] ***************************************************************************
TASK [Gathering Facts] ***************************************************************************
ok: [target1]
TASK [DNS test] ***************************************************************************
changed: [target1]
TASK [Validate DNS server] **************************************************************************
ok: [target1] => {
"msg": "Resolved DNS server 'test.co.com' '24.41.2.5' "
}
TASK [Validate KubeAPI Authentication response as DNS resolve worked] ***************************************************************************
fatal: [target1]: FAILED! => {"audit_id": "59322028-16a5-4c5e-8452-6fcdd308d8d2", "changed": false, "connection": "close", "content": "{\"kind\":\"Status\",\"apiVersion\":\"v1\",\"metadata\":{},\"status\":\"Failure\",\"message\":\"forbidden: User \\\"system:anonymous\\\" cannot get path \\\"/\\\"\",\"reason\":\"Forbidden\",\"details\":{},\"code\":403}\n", "content_length": "185", "content_type": "application/json", "date": "Thu, 26 Sep 2019 01:12:45 GMT", "json": {"apiVersion": "v1", "code": 403, "details": {}, "kind": "Status", "message": "forbidden: User \"system:anonymous\" cannot get path \"/\"", "metadata": {}, "reason": "Forbidden", "status": "Failure"}, "msg": "Status code was not [200]: HTTP Error 403: Forbidden", "redirected": false, "status": 403, "url": "https://testme.co.com", "x_content_type_options": "nosniff"}
PLAY RECAP ***************************************************************************
target1 : ok=3 changed=1 unreachable=0 failed=1
ожидаемый вывод в конце должен иметь эту последнюю строку.
Received 403