Ansible - 如果满足前提条件,则仅运行一系列任务 [英] Ansible - only run a series of tasks if a precondition is met

查看:22
本文介绍了Ansible - 如果满足前提条件,则仅运行一系列任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要从远程 URL 安装的软件包,如下所示:

I have a package I need to install from a remote URL as in:

- get-url: url=http://foo.com/foo.deb dest=/tmp

- command: dpkg --skip-same-version -i /tmp/foo.deb

- apt: update_cache=yes

- apt: pkg=foo state=present

如果 pkg=foo 不存在,我只想运行前 3 个.实现这一目标的最佳方法是什么?

I'd only like to run the first 3 if pkg=foo isn't already present. What's the best way to achieve this?

推荐答案

你必须用结果注册一个变量,然后使用when 语句.

tasks:
  - shell: /usr/bin/foo
    register: result
    ignore_errors: True

  - debug: msg="it failed"
    when: result|failed

这篇关于Ansible - 如果满足前提条件,则仅运行一系列任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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