运行 本地模块

Run a module locally

我正在开发一个烟雾测试剧本,它可以简单地通过并确保我从我们所有的服务器中获得 HTTP 200。

我原来是这样做的:

---
- hosts: prod
  gather_facts: no
  tasks:
      - name: smoke test
        uri: url=http://{{ inventory_hostname }}/ status_code=200

这里的问题是这些服务器显然没有安装 httplib2,所以 URI 命令失败。

有没有办法 运行 我本地机器上的 uri 模块到远程机器 运行 通过所有这些并卷曲每个?如果可能的话,我想使用一个模块,因为它更容易检查 return 代码是否正是我想要的。

您可以使用 delegate_to:

将任何任务委派给本地主机或其他远程主机
- 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