Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is the architecture fact called in Ansible?

Tags:

ansible

I am looking for the fact, which contains the following information:

$ dpkg --print-architecture
amd64

I can not find it:

$ ansible host -m setup | grep amd64
        "BOOT_IMAGE": "/boot/vmlinuz-4.19.0-6-amd64", 
    "ansible_kernel": "4.19.0-6-amd64", 
        "BOOT_IMAGE": "/boot/vmlinuz-4.19.0-6-amd64", 
like image 938
ceving Avatar asked Dec 22 '25 15:12

ceving


2 Answers

Using ansible.builtin.shell is a bad idea. Because it will change the state everytime. I suggest to use mapping with ansible facts.

---
vars:
  deb_architecture: {
    "aarch64": "arm64",
    "x86_64": "amd64"
  }
tasks:
- name: Debug message
  ansible.builtin.debug:
    msg: "{{ [ansible_architecture] | map('extract', deb_architecture) | first }}"

# like example add docker repo
- name: Add Docker APT repository
  ansible.builtin.apt_repository:
    repo: deb [arch={{ [ansible_architecture] | map('extract', deb_architecture) | first }}] https://download.docker.com/{{ ansible_system | lower }}/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} stable
like image 87
Artem Smirnov Avatar answered Dec 24 '25 06:12

Artem Smirnov


You can do (this works on everything):

ansible HOST -m setup -a 'filter=ansible_architecture'

Or (this only works on Debian):

- name: Get DEB architecture
  shell: dpkg --print-architecture
  register: deb_architecture

- name: Print DEB architecture
  debug:
    msg: "deb_architecture.stdout: {{ deb_architecture.stdout }}"

The returned value is:

https://en.wikipedia.org/wiki/X86-64

There might be different systems calling the same architecture using different names because of historical reasons:

https://en.wikipedia.org/wiki/X86-64#History

like image 21
Istvan Avatar answered Dec 24 '25 08:12

Istvan