Ansible> url登录检查一些测试

时间:2017-09-13 12:32:40

标签: ansible

我想通过ansible检查我的应用程序URL。首先,我想检查网址状态,并在登录后使用凭据,并在登录后检查一些测试内容。 但无法做到。

- name: Check url
  uri:
    url: http://192.168.195.210/app

- name: login check
  uri:
    url: http://192.168.195.210/app
    method: GET
    user: Admin
    password: admin
    force_basic_auth: yes
    status_code: 200

让我们知道是否可以这样做?

1 个答案:

答案 0 :(得分:1)

uri模块可以通过启用return_content来返回调用的主体。将其注册到变量并断言其内容。问题中的第一个任务检查/app返回200 OK,考虑到需要基本身份验证,这似乎不合适。

- name: Ensure wrong credentials are unauthorized
  uri:
    url: http://192.168.195.210/app
    user: Admin
    password: "not the admin password"
    force_basic_auth: yes
    status_code: 401

- name: Ensure admin can log in
  uri:
    url: http://192.168.195.210/app
    user: Admin
    password: "{{vault_admin_password}}"
    force_basic_auth: yes
    return_content: yes
  register: login

- name: Ensure user is properly greeted when logged in
  assert:
    that:
    - "'Welcome Admin' in login.content"