我正在开发一个冒烟测试手册,它可以简单地进行检查并确保我从我们的所有服务器中获得 HTTP 200。
我最初是这样做的:
---
- hosts: prod
gather_facts: no
tasks:
- name: smoke test
uri: url=http://{{ inventory_hostname }}/ status_code=200
这里的问题是这些服务器显然没有安装 httplib2,因此 URI 命令失败。
有没有一种方法可以让我在本地计算机上运行 uri 模块到远程计算机,以便运行所有这些模块并 curl 每个模块?如果可能的话,我想使用模块,因为更容易检查返回代码是否正是我想要的。
最佳答案
您可以使用delegate_to
将任何任务委托(delegate)给本地主机或另一个远程主机:
- name: smoke test
uri: url=http://{{ inventory_hostname }}/ status_code=200
delegate_to: localhost
此外,还有 local_action
模块,但我更喜欢 delegate_to
方式。
- name: smoke test
local_action: uri url=http://{{ inventory_hostname }}/ status_code=200
关于ansible - 本地运行模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33791062/