在Ansible Inventory中暂停主机之间的时间

时间:2018-05-15 09:57:48

标签: ansible pause ansible-inventory

我在我的剧本中尝试以下任务。但是没有执行暂停。我想要在删除每个主机后暂停播放30秒。

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模块,但它仍无效。

2 个答案:

答案 0 :(得分:3)

您可以在循环中使用暂停:

- 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

答案 1 :(得分:1)

不幸的是,目前Ansible中不可能将多个任务应用于with_items,但仍然可以使用include directive。例如,

主要播放文件是

---

- 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将是

---
- shell: echo "{{ nagios_host }}"

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

在这种情况下,include语句在循环上执行,循环执行sub_task yml中的所有任务。

相关问题