Ansible - only run a series of tasks if a precondition is met

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 10:51:36

问题


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

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


回答1:


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


来源:https://stackoverflow.com/questions/20858251/ansible-only-run-a-series-of-tasks-if-a-precondition-is-met

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!