如何确保某些 OS 版本和发行版在 运行 ansible 任务之前可用?
How to make sure certain OS version and release is available before running ansible tasks?
我是 ansible 的新手,如果需要,我正在寻找 运行 一些任务的指南 OS version/release 否则会跳过所有任务(即存在消息)。
如果您希望在变量未设置为您想要的值时退出并显示一条消息,则可以使用以下方法:
- name: Fail if not running on CentOS 6
fail: msg="These tasks should only be run on CentOS 6 servers"
when: ansible_distribution != "CentOS" or ansible_distribution_version|int != 6
或者如果变量根本不存在:
- name: Fail if variable foo is unknown
fail: msg="Variable foo is not defined"
when: foo is not defined
如果您想在 OS 不匹配但想继续执行时跳过任务,那么您需要向所有验证 "when" 的任务添加子句=19=]变量。
使用when statement.......
我是 ansible 的新手,如果需要,我正在寻找 运行 一些任务的指南 OS version/release 否则会跳过所有任务(即存在消息)。
如果您希望在变量未设置为您想要的值时退出并显示一条消息,则可以使用以下方法:
- name: Fail if not running on CentOS 6
fail: msg="These tasks should only be run on CentOS 6 servers"
when: ansible_distribution != "CentOS" or ansible_distribution_version|int != 6
或者如果变量根本不存在:
- name: Fail if variable foo is unknown
fail: msg="Variable foo is not defined"
when: foo is not defined
如果您想在 OS 不匹配但想继续执行时跳过任务,那么您需要向所有验证 "when" 的任务添加子句=19=]变量。
使用when statement.......