首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ansible清单中主机之间的暂停时间

Ansible清单中主机之间的暂停时间
EN

Stack Overflow用户
提问于 2018-05-15 17:57:48
回答 2查看 6.7K关注 0票数 3

我正在尝试我的行动手册中的以下任务。但是不执行暂停。我希望在删除每个主机后,播放应该暂停一次30秒。

代码语言:javascript
复制
name: delete host from the NagiosXI
shell: curl -k -XDELETE "https://10.000.00.00/nagiosxi/api/v1/config/host?apikey=qdjcwc&pretty=1&host_name={{ item }}&applyconfig=1"

  - pause:
    seconds: 120

  ignore_error: yes
  with_items:
    - "{{ groups['grp1'] }}"

有人可以建议这是正确的方式,如果做或建议我的正确方式。我也使用了serial=1模块,但它仍然不能工作。

EN

回答 2

Stack Overflow用户

发布于 2018-05-16 01:00:44

你可以在你的循环下使用pause:

代码语言:javascript
复制
- name: Pause
  hosts: all
  gather_facts: False

  tasks:
  - name: delete host from the NagiosXI
    shell: curl -k -XDELETE "https://10.000.00.00/nagiosxi/api/v1/config/host?apikey=qdjcwc&pretty=1&host_name={{ item }}&applyconfig=1"
    ignore_errors: True
    with_items: 
       - "{{ groups['grp1'] }}"
    loop_control:
        pause: 120
票数 6
EN

Stack Overflow用户

发布于 2018-05-15 22:22:19

不幸的是,目前在Ansible中不可能对with_items应用多个任务,但在include directive中仍然可以做到。举个例子,

主播放文件将是

代码语言:javascript
复制
---

- hosts: localhost
  connection: local
  gather_facts: no
  remote_user: me

  tasks:
    - include: sub_play.yml nagios_host={{ item }}
      with_items:
        - host1
        - host2
        - host3

包括在主播中的sub_play yml将是,

代码语言:javascript
复制
---
- shell: echo "{{ nagios_host }}"

- pause:
    prompt: "Waiting for {{ nagios_host }}"
    seconds: 5

在本例中,include语句通过一个循环执行,该循环执行sub_task yml中的所有任务。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50347298

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档