2
Ansible 如何检查一个程序的版本
source link: https://www.lfhacks.com/tech/ansible-check-version/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Ansible 如何检查一个程序的版本
2022-06-08
扫一扫,转发文章
Ansible 如何检查程序输出的版本信息
假如希望检查远程主机上某个程序的版本,如何用 ansible 实现?
比如 python -V
输出版本号
$ python -VPython 3.8.10
为了确保Python 的版本是 3 ,我们可以检查输出中是否包含 “Python 3” 的字符串。
- name: checking version ansible.builtin.shell: cmd: "python -V" register: python_version failed_when: '"Python 3" not in python_version.stderr' changed_when: false...
上面这段 task 中,将 python -V
的输出保存在 python_version
临时变量中,然后检查如果输出中未包含 “Python 3”,就使此次 task 失败。
而 changed_when: false
用来使此次 task 结果不显示为 changed
为了保证阅读体验,本站不安放广告。但是,租用服务器和编写文章需要个人资金和时间的投入。
如果您觉得文章对您有用,请考虑捐助小站(金额不限),以期待更多原创文章。捐助记录
本站是个人网站,若无特别说明,文章均为原创,并采用 署名协议 CC-BY-NC 授权。
欢迎转载,惟请保留原文链接,且不得用于商业用途。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK