我正在尝试编写一个代码,该代码将使用ansible的nagios模块为文件中定义的主机名设置停机时间。我的查询是如何编写代码以遍历包含主机的文件。我的目标是使用此任务
tasks:
- nagios:
author: ansible
action: downtime
minutes: 30
service: all
host: **{{variable value from the file containing hostnames}} ## here is what I want the loop variable should be able to put the hostname extracted from file**
comment: Downtime scheduled deled by Ansible
cmdfile: /usr/local/nagios/var/rw/nagios.cmd
答案 0 :(得分:0)
一种选择是循环 with_lines 。参见下面的示例
- debug: var=item
with_lines: cat /scratch/tmp/test