要确定主机上安装的软件的准确版本,可以使用Ansible的setup模块和facts特性。以下是一个包含代码示例的解决方法:
- name: Get facts of the host
setup:
- name: Get facts of the host
setup:
register: host_facts
- name: Display host facts
debug:
var: host_facts
- name: Display software version
debug:
var: host_facts.ansible_facts.packages[""][0].version
在上述代码中,
是要查找版本的软件名称。
完整的示例代码如下:
- name: Get facts of the host
setup:
register: host_facts
- name: Display host facts
debug:
var: host_facts
- name: Display software version
debug:
var: host_facts.ansible_facts.packages[""][0].version
通过运行上述的playbook,你将能够获取主机上安装的软件的准确版本信息。