9

I'm trying to find the architecture of the machine by using Ansible facts.

We can gather information about the machine by running ansible -m setup <host-name> command, as described in the documentation: Discovering variables: facts and magic variables — Ansible Documentation.

But it seems that the ansible_architecture and ansible_machine are the same values. I'm not sure the difference between them. The example on the above documentation shows the following two values which have the same values:

    "ansible_architecture": "x86_64",
    "ansible_machine": "x86_64",

On my M1 MacBook, the result is the same like this:

shuuji3@momo mac-dev-playbook
> ansible -m setup localhost | egrep '_architecture|_machine'
        "ansible_architecture": "arm64",
        "ansible_machine": "arm64",

Can we use these values interchangeably? Or can they have other values in another case?

U880D
  • 8,601
  • 6
  • 24
  • 40
shuuji3
  • 1,233
  • 13
  • 20

1 Answers1

8

According to the code (https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/facts/system/platform.py) it's mostly always the same.

The value can differ on Solaris, AIX and OpenBSD.

I guess ansible_machine is supposed to be the machine architecture (value of platform.machine() https://docs.python.org/3/library/platform.html), while ansible_architecture is more the OS architecture?

zigarn
  • 10,892
  • 2
  • 31
  • 45
  • Thanks for the clear explanation. I can understand why the names are machine and architecture. – shuuji3 Mar 28 '21 at 04:00
  • 2
    I found the `x86_64` is returned under Rosetta 2 emulation (Intel mode). See also: https://stackoverflow.com/q/66839206/1204782 and https://stackoverflow.com/q/65970469/1204782 – shuuji3 Mar 28 '21 at 07:16