ansible_architecture
和 ansible_machine
都是 Ansible 的预定义变量,它们都提供了关于远程主机的一些基本信息。二者的区别在于,ansible_architecture
提供了远程主机的 CPU 架构信息,比如 x86_64、i386 等;而 ansible_machine
则提供了远程主机的操作系统类型和硬件架构的组合,比如 x86_64、Linux 等。
下面是一个简单的代码示例,演示如何使用这两个变量:
- name: Display remote host architecture information
hosts: myserver
gather_facts: no
tasks:
- name: Show remote machine architecture
debug:
var: ansible_architecture
- name: Show remote machine architecture and OS type
debug:
var: ansible_machine
在上面的示例中,我们先定义了一个名为 myserver
的主机名,然后使用 debug
模块来显示远程主机的架构信息。第一个 debug
模块仅使用 ansible_architecture
变量来输出 CPU 架构信息;第二个 debug
模块使用 ansible_machine
变量来输出操作系统类型和 CPU 架构的组合信息。