Ansible-仅在满足先决条件的情况下运行一系列任务 [英] Ansible - only run a series of tasks if a precondition is met

查看:108
本文介绍了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?

推荐答案

您必须 .

You have to register a variable with the result, and then use when statement.

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

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

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

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