多个 Ansible 任务的一个循环 [英] One loop over multiple Ansible tasks

查看:33
本文介绍了多个 Ansible 任务的一个循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 Ansible playbook,它创建了一个云实例,然后在该实例上安装了一些程序.我想多次运行这个剧本(不使用 bash 脚本).是否可以使用循环将这两个任务一起循环(即两个任务的一个循环?).到目前为止我能找到的只是每个单独任务的一个循环

解决方案

不,目前不可能.with_items 曾经在 Ansible 的早期版本中使用 include 语句,但不幸的是被删除了.

虽然它会在 Ansible 2.0 中恢复,请参阅 ,该功能应该是在那里可用.

您可以使用 1.9.1 做的是将您的任务转移到一个角色中,并在您的剧本中多次引用该角色.

I've created an Ansible playbook that creates a cloud instance and then installs some programs on the instance. I want to run this playbook multiple times (without using a bash script). Is it possible to use a loop to loop over those two tasks together (I.E. One loop for two tasks?). All I've been able to find so far is one loop for each individual task

解决方案

No that's currently not possible. with_items used to work with the include statement in previous versions of Ansible but was unfortunately dropped.

Though it will be brought back in Ansible 2.0, see slide 14/15 of What's New in v2 - AnsibleFest London 2015

You could try to work with the v2 branch from github, the feature should be available in there.

What you can do with 1.9.1 is to move your tasks into a role and reference this role multiple times in your playbook.

这篇关于多个 Ansible 任务的一个循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆